regex

regex to find a word in a sentence

I have a string like following: CREATE GLOBAL TEMPORARY TABLE some_temp_table_name OR CREATE GLOBAL TEMPORARY TABLE some_temp_table_name something else with the regex I want to strip out whatever is in bold letters. I have the following regex ([a-z].*[\s]*) what should I change in the regex? ...

.NET Regular expression for time 24 hr format

Hi, Can I please have a regular expression in .NET, which will allow only 24 hr time format in the textbox. Thanks. Best Regards, MS ...

Match multiple patterns in a multiline string

Hi, I have some data which look like that: PMID- 19587274 OWN - NLM DP - 2009 Jul 8 TI - Domain general mechanisms of perceptual decision making in human cortex. PG - 8675-87 AB - To successfully interact with objects in the environment, sensory evidence must be continuously acquired, interpreted, and used to guide appropriat...

PHP ereg vs. preg

I have noticed in the PHP regex library there is a choice between ereg and preg. What is the difference? Is one faster than the other and if so, why isn't the slower one deprecated? Are there any situations where it is better to use one over the other? ...

PHP ereg_replace questions

A couple of PHP ereg_replace questions. I have an array of names: $ssKeywords = array("Str", "Int", "String", "As", "Integer", "Variant"); However when I use this ereg_replace: foreach($arKeyword as $aWord) { $sCode = ereg_replace($aWord, "<span class='ssKeyword'>".$aWord."</span>", $sCode); } It will only find the "str" or "int"...

How to strip characters between HTML tags

I have the following HTML: <h1>Text Text</h1> <h2>Text Text</h2> I am still trying to get a handle on regular expressions, and trying to create one that would eliminate the spacing between the tags. I would like the final result to be: <h1>Text Text</h1><h2>Text Text</h2> Any help would be greatly appreciated! UPDATE I wou...

Javascript Regexp not returning global results

It's my understanding that all three of these lines below should return an ARRAY with 2 results in it. Yet RegExp will only return 1 result no matter how many times the regex repeats in the string. Can some one explain why? And perhaps suggest how I can get RegExp to give me global results? //INTPUT: console.log(new RegExp("New Yo...

replacing all image src tags in HTML text

Hi! I'm trying to make a simple php script to find all src attributes from all images in a html text and then replace all found srcs with some text after making some conditional changes. Something like this: @preg_match_all('/<img\s src="([a-zA-Z0-9\.;:\/\?&=_|\r|\n]{1,})"/isxmU', $body, $images); now i've all srcs into the $images ...

Problem creating regex to match filename

I am trying to create a regex in C# to extract the artist, track number and song title from a filename named like: 01.artist - title.mp3 Right now I can't get the thing to work, and am having problems finding much relevant help online. Here is what I have so far: string fileRegex = "(?<trackNo>\\d{1,3})\\.(<artist>[a-z])\\s-\\s(<title...

Regex expression challenge

Can somebody put a regex expression that will: find a chunk that starts with [% and ends with %] within that chunk replace all xml special characters with: & quot; & apos; & lt; & gt; & amp; leave everything between <%= %> or <%# %> as is except make sure that there is space after <%# or <%= and before %> for example <%=Integer.Max...

regex over multiple lines in groovy

I have a multiple line string like following: END IF; **EXECUTE IMMEDIATE ' CREATE INDEX #idx1 ON somename ( row_id, something)';** IF v_sys_error <> 0 THEN GOTO SQL_ERROR; END IF; Edit: '**' is not in my string. I wanted to bold what i wanted to capture. I wish to capture the part in ...

Capturing inner items using .net Regex Balanced Matching

I have found the following resources on Balanced Matching for .net Regexes: http://weblogs.asp.net/whaggard/archive/2005/02/20/377025.aspx http://blogs.msdn.com/bclteam/archive/2005/03/15/396452.aspx http://msdn.microsoft.com/en-us/library/bs2twtah%28VS.85%29.aspx#BalancingGroupDefinitionExample From what I have read in these, the fo...

PHP regular expressions to clean duplicated HTML tags

I am trying to get a regular expression to work, but not having a whole lot of luck. the source file I am reading(poorly formatted, but nothing I can do there) has the following in its source between elements <BR> <BR> <BR> how do I match this with a php regular expression? ...

How can I have a minimal match between two known tokens?

I have a selection of text that looks like the following. I need to do a rudimentary edit on it, but can't fathom the regex that I need. Maybe it's just been a long day, and I'm not seeing what I need. Sample data: START ITEM = 1235 BEGIN WORD RATE = 98 MORE WORDS CODE = XX STUFF END ...

Whitespace woes in Regex

I am using a simple Perl script to parse XML and convert it to usable SQL. My current SQL lines go something like this: INSERT INTO table VALUES ('data1', 'data2', 'data3', ); Obviously I need to remove the comma at the end there. Sounds simple but I just can't get regex to find it. I tried s/,\s+)/)/ but that doesn't change anything...

Regex with not match at end

I'm trying to write a regex to match patterns like this: <td style="alskdjf" /> i.e. a self terminating <td> but not this: <td style=alsdkjf"><br /></td> I initially came up with: <td\s+.*?/> but that obviously fails on the second example and I thought that something like this might work: <td\s+.*?[^>]/> but it doesn't. I'm ...

PHP regular expression to remove tags in HTML document

Say I have the following text ..(content)............. <A HREF="http://foo.com/content" >blah blah blah </A> ...(continue content)... I want to delete the link and I want to delete the tag (while keeping the text in between). How do I do this with a regular expression (since the URLs will all be different) Much thanks ...

Java RegExp problem

Hi guys, I'm trying to get a regexp to solve the next problem: I have some strings with the next format "somename 1 of 20 and something else" I want to retrieve the "1" from the string I'm trying with Pattern pat = Pattern.compile("(?<!of\\s)(\\d+)\\s", Pattern.CASE_INSENSITIVE); Matcher matcher = pat.matcher(tmp); But doesn't wor...

How do I use this regular expression? (Aweber Email Parser)

Hello All, I'm having a bit of difficulty figuring out how to use this Regular Expression which Aweber provides for email parsing. I'm supposed to be able to send an email to aweber, with this ruleset, and aweber will add the email to my list. Here is the rule: Trigger Rule: From:[^\n|.]+user\@domain\.com | MATCH HEADERS Rule 1: ...

How do I replace "new line" characters inside double quotes in php?

Ok, I have a csv file like this: 14 ; 1234,56 ; 10203 ; "ABC" ; "DFG" ; "Lorem \n ipsum \n dolor sit" \n 15 ; 234,16 ; 10204 ; "ABC" ; "DFG" ; "Lorem \n ipsum \n dolor sit" \n 16 ; 1234,15 ; 10304 ; "CCC" ; "DFG" ; "Lorem ipsum/dolor \n sit amet\consec" \n and so on... The file has almost 550000 lines. How do I replace all \n charact...