regex

Conditional regex problem

Dear all, I've a regular expression problem, and I guess I'm missing a point in how the regex actually work. I've some set of strings that contains methods definitions myMethod1() myMethod2(argument1 arg1) myMethod3(argument1 arg1, argument2 arg2) but some of them also contains the output type: myOtherMethod1() : type1 myOtherMe...

Regex issue with reserved characters in c#

I've got a working regex that scans a chunk of text for a list of keywords defined in a db. I dynamically create my regex from the db to get this: \b(?:keywords|from|database|with|esc\@ped|characters|\@ss|gr\@ss)\b Notice that special characters are escaped. This works for the vast majority of cases, EXCEPT where the first character o...

Regex for string with spaces and special characters - C#

Hello there, I have been using Regex to match strings embedded in square brackets [*] as: new Regex(@"\[(?<name>\S+)\]", RegexOptions.IgnoreCase); I also need to match some codes that look like: [TESTTABLE: A, B, C, D] it has got spaces, comma, colon Can you please guide me how can I modify my above Regex to include such codes. P.S...

Replacing all special characters with a Regular Expression

I am trying to replace all German special characters in a Regular Expression. The Characters are ä ö ü ß ...

Merge several regexes to a single one

I have several regexes (actually several thousands), and I must check if one string matches any of these regexes. It is not very efficient, so I would like to merge all these regexes as a single regex. For example, if a have these regexes: 'foo *bar' 'foo *zip' 'zap *bar' I would like to obtain something like 'foo *(bar|zip)|zap *ba...

Matching the first <p> that does not start with an image in regexp

In PHP, I'm trying to match the first paragraph tag that is not immediately followed by an <img> tag, and add a class to that paragraph tag. For example, it would add a class to: <p>Text</p> and <p><strong>Strong text</strong></p> but not: <p><img src="" /></p> Here's what I have so far which successfully adds a class to the fi...

Intelligent RegEx in Perl?

Background Consider the following input: <Foo Bar="bar" Baz="1" Bax="bax" > After processing, I need it to look like the following: <Foo Bar="bar" Baz="1" Bax="bax" CustomAttribute="TRUE" > Implementation This is all I need to do for no more than 5 files, so using anything other than a regular expr...

PHP syntax error on preg_replace method

Hello, I'm trying to do a bbcode parser class that can create personalyzed tags, but I have some problem with urls I've did all I need without particular problems thanks to regular expressions but I have a problem when I try to create a special tag who point to a specified URL. In my class I've added a method like this: <? private...

How to get the last segment with regular expression?

I have the following url. http://127.0.0.1/ci/index.php/admin/menus/edit/24 I want to get 24 from this to use in jquery/javascript. Something like this. var id=this.href.replace(/.*=/,''); this.id='delete_link_'+id; Could anyone tell me how to code this? ...

regex question redux regarding definition list

Trying to figure out a way to throw out attributes in this data that do not have any values. Thanks for helping. My current regex code , thanks to Tomalak looks like this Regex find ([^=|]+)=([^|]+)(?:\||$) Regex replace <dt>$1</dt><dd>$2</dd> Data looks like this Bristle Material=|Wire Material=Steel|Dia.=4 in|Grit=|Bristle ...

.htaccess remove file extension before hashtag

http://freddygonzalez.me/dev/update/index.html#mywork.html How can I use .htaccess to remove the index.html So it could look like this http://freddygonzalez.me/dev/update/#mywork.html Also there may be one conflict.If the user press on the logo they get this http://freddygonzalez.me/dev/update/index.html#index.html So is there a way ...

How can I match "/*" in a regular expression?

Hello all. $stuff = "d:/learning/perl/tmp.txt"; open STUFF, $stuff or die "Cannot open $stuff for read :$!"; while (<STUFF>) { my($line) = $_; # Good practice to always strip the trailing chomp($line); my @values = split(' ', $line); foreach my $val (@values) { if ($val == 1){ print "1 found"; ...

.net mvc routing greedy regex

In my global.asax.cs file. I add an entry routes.MapRoute( "Static text", "Static/General/{filePath}", new { controller = "Static", Action = "General", filePath = "" }, // new { filePath = @"xxxx" } // greedy regular expression ); What I want to do is to take the content f...

preg_replace to remove empty tags but keep the end of blockquotes

Hi, I made this expression to remove all empty (inluding tags with just whitespace) tags in the page. $content = preg_replace('/<[^\/>]*>([\s]?)*<\/[^>]*>/', '', $content); It worked a treat until it had to deal with content like this... <blockquote> <p >foo bar</p> </blockquote> <p ><a href="image.jpg" rel="lightbox" title=""><im...

Extracting a Date from "the meeting is on 12-DEC-2009 at 13:00" with Groovy

As the title states I have a string similar to: "lorem ispom 12-DEC-2009 fsasdfsd 12:00" OR "the meeting is on 12-DEC-2009 at 13:00" And I need to extract a Date with time from this. What is an elegant and robust way of doing this in Groovy ...

Quick fix for splitting a string using regexp

I used the following Regex RE = new Regex(@"'?([(\.\//\s\;\,\:\.\)]+)'?"); to split the expression which is stored in an xml file. "NIGHT.set('/xs:Service/xs:Location[2]/xs:Res/protocol','HOPR','SP')"; It craps out when reading it, because of the single quotes. I want to get rid of the single quotes in the xml file, changing the...

Is regex in Java anchored by default with both a ^ and $ character?

From my understanding of regular expressions string "00###" has to match with "[0-9]", but not to "^[0-9]$". But it doesn't work with Java regexp's. After some investigating of this problem I founded next information (http://www.wellho.net/solutions/java-regular-expressions-in-java.html): It might appear that Java regular expressi...

Elegant regular expression to match all punctuations but not "'" in emacs Lisp?

I want to match all punctuations, but not "'", as in "I'm". For example, in the sentence below: I'm a student, but I'm also working. ^not match ^match ^not ^match I can use "[[:punct:]]+" to match all punctuations, but I'm having hard time to exclude "'" from the matching pattern. Of course, I could use someting like the...

Regex HTML Extraction C#

I have searched and searched about Regex but I can't seem to find something that will allow me to do this. I need to get the 12.32, 2,300, 4.644 M and 12,444.12 from the following strings in C#: <td class="c-ob-j1a" property="c-value">12.32</td> <td class="c-ob-j1a" property="c-value">2,300</td> <td class="c-ob-j1a" property="c-value">...

How can I create a regular expression in Python?

I'm trying to create regular expressions to filter certain text from a text file. What I want to filter has this format: word_*_word.word So for example, I would like the python code every match. Sample results would be: program1_0.0-1_log.build program2_0.1-3_log.build How can I do this? Thanks a lot for your help ...