Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression with an = and a ;

Tags:

I'm trying to use a regular expression to find all substrings that start with an equals sign (=) and ends with a semicolon (;) with any number of characters in between. It should be something like this =*;

For some reason, the equals is not registering. Is there some sort of escape character that will make the regex notice my equals sign?

I'm working in Java if that has any bearings on this question.

like image 655
chama Avatar asked Feb 16 '10 16:02

chama


1 Answers

This may be what you are looking for. You need to specify a character set or wild card character that you are applying the asterisk to.

"=([^;]*);" 

You can also use the reluctant quantifier:

"=(.*?);" 

Using the parenthesis you now have groups. I believe the first group is the whole entire match, and group[1] is the group found within the parenthesis.

The code may look something like:

Regex r = new Regex("=([^;]*);"); Match m = r.Match(yourData); while (m.Success) {     string match = m.Groups[1];     // match should be the text between the '=' and the ';'. } 
like image 63
jjnguy Avatar answered Oct 09 '22 16:10

jjnguy