Anybody know regex?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BigBen
    Confirmed User
    • Nov 2004
    • 2299

    #1

    Anybody know regex?

    What's a regular expression that will find all occurences of anything between the following characters: {$ and }

    So if I have some text: "The site name is {$site}", I need to match 'site'. It has to be greedy as there may be multiple matches.

    Any ideas? Thanks.
  • J.P.
    Confirmed User
    • Jun 2004
    • 689

    #2
    try using this:

    /\{\$[^\}]+\}/


    BTW:
    "greedy regexp" does not have anything to do with multiple matches...

    if you would use /\{\$.*\}/ on "hello {$site} and a happy new {$what}"

    greedy regexp would match a "{$site} and a happy new {$what}" and the non-greedy one would match a "{$site}" and "{$what}"
    Webmasters! Looking for new affiliate programs to promote?
    Affiliate Program Search <-- Search for programs with FHGs, RSS feed, specific niche sponsors, ...

    Comment

    • BigBen
      Confirmed User
      • Nov 2004
      • 2299

      #3
      Originally posted by J.P.
      try using this:

      /\{\$[^\}]+\}/


      BTW:
      "greedy regexp" does not have anything to do with multiple matches...

      if you would use /\{\$.*\}/ on "hello {$site} and a happy new {$what}"

      greedy regexp would match a "{$site} and a happy new {$what}" and the non-greedy one would match a "{$site}" and "{$what}"
      That works perfect, thanks.

      Comment

      • J.P.
        Confirmed User
        • Jun 2004
        • 689

        #4
        no problem, anytime
        Webmasters! Looking for new affiliate programs to promote?
        Affiliate Program Search <-- Search for programs with FHGs, RSS feed, specific niche sponsors, ...

        Comment

        Working...