Skip to the posts
Buffalo's neighborhood journals since 2003 🍀 Patrick Spicy Devil Logan🌭 Sahlen🥨 Weber Spank🥟 Pierogi🐸 Scaj🍺 Labatt Utica Pink Cherio❄️ Snow Murder

tinypliny’s journal

Clueless about regex

·

What I want to do is match strings with regular expressions.

^ : start of string
[ : beginning of character group
a-z : any lowercase letter
A-Z : any uppercase letter
0-9 : any digit
_ : underscore
] : end of character group
* : zero or more of the given characters
$ : end of string


Now I can't even write code for matching a variable length sentence or phrase in curly brackets for example:

{A quick brown FOX jumps over a sprightly hare}

Hmm... this does not work
(\{)[.*?](\})

This doesn't work
(\\{).*?(\\})

This doesn't work either.
\\{.*?\\}

ARRRGH.
It's funny how it's called regular.

References

1.
2.
3.
4.
Share 119 words · edited Oct 4, 2011

💬 4 comments

  1. paul ·

    I use \w (letters and _ ) and \d (digit) a lot. Here is some PHP for what I think you are trying to match. PHP uses PERL Compatible Regular Expressions. You have to have a begin and end delimiter in PHP and you have to escape the curly brackets because they are used to mark repetition. e.g. \d{3} means any 3 digits or \d{1,2} any one or two digits.



    Array
    (
    [0] => {A quick brown FOX jumps over a sprightly hare}
    [1] => A quick brown FOX jumps over a sprightly hare
    )
  2. paul ·

    Sorry it did not come out:
    $str = '{A quick brown FOX jumps over a sprightly hare}';
    preg_match("/\{(.*?)\}/", $str, $matches);
    print_r($matches);
  3. paul ·

    Matches result is shown in the first comment.
  4. tinypliny ·

    Thanks!! :) I am going to bug you with regex questions....

💬 Write a comment