none
What does this Regex do? RRS feed

  • Question

  • Can you describe what the following Regex does?

    keywords is a string of words separated with |

    substring is just some text

      Dim keywordRegEx As New Regex("(?<=\s|{|}|\(|\)|,|\=|^)(" & keywords & ")\b")

    later

      For Each mtch As Match In keywordRegEx.Matches(substring)

    Tuesday, May 16, 2017 11:40 PM

Answers

  • RegexBuddy says:

    (?<=\s|{|}|\(|\)|,|\=|^)(key|word|One|Two)\b

    Options: dot matches newline

    Assert that the regex below can be matched, with the match ending at this position (positive lookbehind) «(?<=\s|{|}|\(|\)|,|\=|^)»
       Match either the regular expression below (attempting the next alternative only if this one fails) «\s»
          Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s»
       Or match regular expression number 2 below (attempting the next alternative only if this one fails) «{»
          Match the character “{” literally «{»
       Or match regular expression number 3 below (attempting the next alternative only if this one fails) «}»
          Match the character “}” literally «}»
       Or match regular expression number 4 below (attempting the next alternative only if this one fails) «\(»
          Match the character “(” literally «\(»
       Or match regular expression number 5 below (attempting the next alternative only if this one fails) «\)»
          Match the character “)” literally «\)»
       Or match regular expression number 6 below (attempting the next alternative only if this one fails) «,»
          Match the character “,” literally «,»
       Or match regular expression number 7 below (attempting the next alternative only if this one fails) «\=»
          Match the character “=” literally «\=»
       Or match regular expression number 8 below (the entire group fails if this one fails to match) «^»
          Assert position at the beginning of the string «^»
    Match the regular expression below and capture its match into backreference number 1 «(key|word|One|Two)»
       Match either the regular expression below (attempting the next alternative only if this one fails) «key»
          Match the characters “key” literally «key»
       Or match regular expression number 2 below (attempting the next alternative only if this one fails) «word»
          Match the characters “word” literally «word»
       Or match regular expression number 3 below (attempting the next alternative only if this one fails) «One»
          Match the characters “One” literally «One»
       Or match regular expression number 4 below (the entire group fails if this one fails to match) «Two»
          Match the characters “Two” literally «Two»
    Assert position at a word boundary «\b»

    • Marked as answer by scholarQ Wednesday, May 17, 2017 1:46 PM
    Wednesday, May 17, 2017 1:11 AM

All replies

  • RegexBuddy says:

    (?<=\s|{|}|\(|\)|,|\=|^)(key|word|One|Two)\b

    Options: dot matches newline

    Assert that the regex below can be matched, with the match ending at this position (positive lookbehind) «(?<=\s|{|}|\(|\)|,|\=|^)»
       Match either the regular expression below (attempting the next alternative only if this one fails) «\s»
          Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s»
       Or match regular expression number 2 below (attempting the next alternative only if this one fails) «{»
          Match the character “{” literally «{»
       Or match regular expression number 3 below (attempting the next alternative only if this one fails) «}»
          Match the character “}” literally «}»
       Or match regular expression number 4 below (attempting the next alternative only if this one fails) «\(»
          Match the character “(” literally «\(»
       Or match regular expression number 5 below (attempting the next alternative only if this one fails) «\)»
          Match the character “)” literally «\)»
       Or match regular expression number 6 below (attempting the next alternative only if this one fails) «,»
          Match the character “,” literally «,»
       Or match regular expression number 7 below (attempting the next alternative only if this one fails) «\=»
          Match the character “=” literally «\=»
       Or match regular expression number 8 below (the entire group fails if this one fails to match) «^»
          Assert position at the beginning of the string «^»
    Match the regular expression below and capture its match into backreference number 1 «(key|word|One|Two)»
       Match either the regular expression below (attempting the next alternative only if this one fails) «key»
          Match the characters “key” literally «key»
       Or match regular expression number 2 below (attempting the next alternative only if this one fails) «word»
          Match the characters “word” literally «word»
       Or match regular expression number 3 below (attempting the next alternative only if this one fails) «One»
          Match the characters “One” literally «One»
       Or match regular expression number 4 below (the entire group fails if this one fails to match) «Two»
          Match the characters “Two” literally «Two»
    Assert position at a word boundary «\b»

    • Marked as answer by scholarQ Wednesday, May 17, 2017 1:46 PM
    Wednesday, May 17, 2017 1:11 AM
  • Note: The email answer I received (Alert) from Viorel does not show here! I'd like to mark it as an answer.

    =====

     what does the /b (backspace) do


    • Edited by scholarQ Wednesday, May 17, 2017 5:00 PM Was not a good question
    Wednesday, May 17, 2017 4:57 PM
  • Is the result basically different from:

    "\b" & temp & "\b"

    Tuesday, July 4, 2017 1:13 PM