Escaping in Assertions

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Sythus
Forum Newbie
Posts: 1
Joined: Sun Sep 30, 2012 11:42 am

Escaping in Assertions

Post by Sythus »

Hello everybody,

i have the following string:
[text]
Ref-Nr. : xai2i31iw
[/text]

and i'm trying to get "xai2i31iw" as value with preg_match.

I'm struggling with escaping the Ref-Nr.
i tried the following regex with a look behind assertion: [text]#(?<=Ref\-Nr\.\:).*#[/text]
But it doesn't work...

I would appreciate every help because i'm pretty new to regular expressions and google / forums search don't bring up any information that help me solving this problem.

Thanks :D

Sythus
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Escaping in Assertions

Post by twinedev »

Here is something

Code: Select all

$subject = "Ref-Nr.         : xai2i31iw";

if (preg_match('/Ref-Nr\.\s*?:\s*?([a-z0-9]+)/', $subject, $regs)) {
    $result = $regs[1];
}
else {
    $result = FALSE;
}
A great program for helping with RegEx's is my favorite, RegexBuddy.
Post Reply