Need some help with regular expressions

Recommended Videos

vehystrix

New member
Nov 18, 2009
151
0
0
I'm thinking that this is the place to post such topic, but if it isn't just move it to wherever it is appropriate, thx.

Ok, so I'm not all that good with regular expressions, but I get the basics. I want to match anything that is not a lower case letter, number or mathematical character (+,-,*,/,.,(,),^,E). Additionally, it should match any 2 letters following eachother, a letter followed by one or more numbers, and one or more numbers followed by a letter.

The expression I cooked up is the following:
([^\^\-+\*/a-z0-9E\(\)\.])|([a-z]{2,})|([a-z][0-9]+)|([0-9]+[a-z])
The error I'm getting however is:
Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '|' in F:\wamp\www\plot_processed.php on line 52
Which leeds me to believe there's something wrong with the alternating |, but I cannot find my mistake.

Anyone with some regex knowledge care to shed any light on this? I can elaborate more on its purpose if necessary, but I believe that this should suffice.

Thx in advance,
VEH
 

dmase

New member
Mar 12, 2009
2,117
0
0
I'm not sure what type of code you are doing but i use C++ for my class and when we compare things you must use two ||. && that type of thing.

You doing a final project or for fun?
 

vehystrix

New member
Nov 18, 2009
151
0
0
Anarchemitis said:
What does ^\^\-+\ mean?
the first ^ means that it will match anything that is not contained within the square brackets. The \^ means to match the ^ character, but it is escaped by a \ since it is a special character. The \- means to match the - character, but since - is also a special character it is also escaped with a \. + means to match the + character, and \* means to match the * character, but again * is a special character so it is escaped by a \. I hope that clears up the awkward use of backslashes in there.

dmase said:
I'm not sure what type of code you are doing but i use C++ for my class and when we compare things you must use two ||. && that type of thing.

You doing a final project or for fun?
I use PHP to code everything, and there it also is || and && instead of | and &. However, in regular expressions, this is not the case (or so far as I can find in the references on the internet)

This is part of my thesis work, so kinda important. It's still for fun too tough =P
 

dmase

New member
Mar 12, 2009
2,117
0
0
vehystrix said:
Anarchemitis said:
What does ^\^\-+\ mean?
the first ^ means that it will match anything that is not contained within the square brackets. The \^ means to match the ^ character, but it is escaped by a \ since it is a special character. The \- means to match the - character, but since - is also a special character it is also escaped with a \. + means to match the + character, and \* means to match the * character, but again * is a special character so it is escaped by a \. I hope that clears up the awkward use of backslashes in there.

dmase said:
I'm not sure what type of code you are doing but i use C++ for my class and when we compare things you must use two ||. && that type of thing.

You doing a final project or for fun?
I use PHP to code everything, and there it also is || and && instead of | and &. However, in regular expressions, this is not the case (or so far as I can find in the references on the internet)

This is part of my thesis work, so kinda important. It's still for fun too tough =P
Seems like you could teach me more than i could help you. yeah i'm doing my final two programs for my class and i can't consider any of the stuff i'm doing fun, probably because I get frustrated by it.

If you need some help i'd join this user group.

http://www.escapistmagazine.com/groups/view/The-Escapist-Programmers-Help-Group

I'm gonna guess these guys haven't been looking at their group page in awhile so if you have some time to wait for a reply just message a few of the senior members they might be online tho so just start a chat if there is someone online.