SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)

    Regex Match Quotation Marks

    Hello,

    I wrote a regex to match some stuff. It's essentially matching some PHP code. I want to be able to match the quotation marks, but only the pairs.

    So, for example, if I have something like:
    ['"](.*)['"]

    I want the second ['"] to only match the same one as the first, so:
    "A"
    'A'

    should match, but not
    "A'
    'A"
    (and ultimately) "Something 'random'"

    Any ideas?

    Thanks.

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    So, along the same lines, I have this regex (in PHP):
    "/(get_)?the_block\(\s?['\"](?P<id>[^'\"]*)['\"]\s?(,\s?['\\\"](?P<title>.*)['\"])?\s?\)/"

    It matches basically a function call which looks like:
    get_the_block('a','b')

    (with 'b' being optional).

    It's working for single-quotes, but for some reason it doesn't with double-quotes. Any idea?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •