Regex Question

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

Moderator: General Moderators

Post Reply
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Regex Question

Post by Sphenn »

Hello everyone.

I am trying to build a regex that will take information from between two delimiters.

The delimiters are "{" and "}". I'm trying to get everything in between those two characters.

I've looked at all the tutorials, but I don't really have a clue.

If anyone could give me a few pointers, that would be great

Thanks,

Sphenn
RobertPaul
Forum Contributor
Posts: 122
Joined: Sun Sep 18, 2005 8:54 pm
Location: OCNY

Post by RobertPaul »

Well ...

Code: Select all

/\{.*\}/
That would do it.
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

I would use

Code: Select all

/{([^}]+)}/
... the negated } will be faster than having to backtrack...

(untested)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

to create a reference...

Code: Select all

$pattern = /\{(.*?)\}/;

edit:
damn it! I guess the bbcode or something is killing my escape slashes...there needs to be backslashes right before the { and }
Post Reply