regular expression not working

Alles, was PHP betrifft, kann hier besprochen werden.

regular expression not working

Postby pathfinder80 » 25. July 2007 17:27

regular expression: "^\"[^\"\\\r\n\t]*(\\.[^\"\\\r\n\t]*)*\"$"

I working on parsing strings in a file. I have stored all the strings in an array and using the above given pattern to parse the strings(using the ereg function in PHP).
1)My strings should be within double quotes.
2) There should be no other double or single quotes inside the string.
3) But there can exists \" or \' or \ in the string.( the double or single quotes can exists wih a backslash).
4) There should be no tabs inside the double quotes of the string.
5) The string may also be UTF8 characters (any language strings including asian languages).

The above pattern works fine when I try them in the RegexBuddy which is a regular expression tool. But is not working in my code.

Thanks in advance.
pathfinder80
 
Posts: 12
Joined: 26. June 2007 22:13

Postby KingCrunch » 25. July 2007 17:58

You have to enclose them with Delimiters. The Delimiter is a character of your choice, but you have to escape it, when you want to use it in your regex. So ~ is often a good choice, cause its used very rarely in regex itself. The starting Delimiter has to be the first character of your regex-String, after the trailing Delimiter there can additional modifiers.
Code: Select all
$regex = '~' . $regex . '~';
Nicht jeder Fehler ist ein Bug ...
KingCrunch
 
Posts: 1724
Joined: 26. November 2005 19:25

Postby pathfinder80 » 25. July 2007 18:08

I tried this but it displays all the valid strings as not matched strings. The pattern that I am using checks if there is a double quotes inside a string(It says that the string is invalid as I dont want any double quotes in my string) but the pattern is not working for the tab and other rules i have specified in my previous message.
pathfinder80
 
Posts: 12
Joined: 26. June 2007 22:13

Postby Mätes » 26. July 2007 11:54

try it withot ^ and $

"\"[^\"\\\r\n\t]*(\\.[^\"\\\r\n\t]*)*\""

with this characters he searches for a WHOLE LINE (from the first
to the last character) that does contain your seach-string,
and not a line, that does contain something else AND your search-string.

g
ma
User avatar
Mätes
 
Posts: 142
Joined: 13. April 2006 09:34
Location: kölle


Return to PHP

Who is online

Users browsing this forum: No registered users and 3 guests