1

I have a query string parameter looks like below:

Nr=AND(OR(abc:def),OR(ghi:jkl),OR(mno:pqr).....so on)

I wanted to replace this query string to get the values inside the OR condition delimited between colon.

any help will be appreciated.!!

8
  • This ain't valid JavaScript, or a RegEx. Are you missing any tags? Commented Jun 23, 2014 at 11:41
  • Have you tried something yet? Commented Jun 23, 2014 at 11:42
  • this query string based on the search with form values getting appended to get the result from back-end. Commented Jun 23, 2014 at 11:44
  • What would be your expected output? Commented Jun 23, 2014 at 11:48
  • 1
    OR\(([^:]*):([^)]*)\) this would capture the text inside OR function and stored it into two seperate groups. Commented Jun 23, 2014 at 11:54

1 Answer 1

1

The below regex would capture the text inside OR function and stored it into two separate groups using : as delimiter,

OR\(([^:]*):([^)]*)\)

DEMO

Explanation:

  • OR\( Matches literal OR(.

  • ([^:]*) NOt of : character zero or more times. Finally it stores the matched characters into group1.

  • : A literal :

  • ([^)]*) Not of a literal ) character zero or more times. Finally it stores the matched characters into group2.

  • \) Matches a literal ) character.

Sign up to request clarification or add additional context in comments.

3 Comments

It is matching all the OR values perfectly..but the array value returs only the first OR value only...For Ex. AND(OR(abc:def),OR(ghi:jkl),OR(mno:pqr)...). Above regex return only the abc:def value only.
In the demo it matches both. I think, some modifications would be done on your code only. You can ask it as another question.
+1 for concise solution with explanation and working demo. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.