0

Need help finding out the regex pattern that will help me replacing below -

*LABEL and it’s value which contains within double quote. (Text within double quotes may contain all different special characters and there is no fix pattern)

I am giving 2 different examples -

Input String 1 -

*QUESTION 99924 *ALPHA 1026L3 *DUMMY *VAR “version” *LABEL “SCRIPT VERSION” *PROPERTIES “ReportType=IsShell;ExcludeFromDAU=True”

Expected Output String -

*QUESTION 99924 *ALPHA 1026L3 *DUMMY *VAR “version” *PROPERTIES “ReportType=IsShell;ExcludeFromDAU=True”

Input String 2 -

*QUESTION 270 *CODES 4705L996 *RANDOM *MULTI *MIN 1 *LABEL “BARRIERS_TO_ATTENDENCE - B3” *VAR “BARRIERS_TO_ATTENDENCE” *PROPERTIES “DIMVAR=BARRIERS_TO_ATTENDENCE” *IF [#Q180,1] UIOPTIONS "? ROWPICKER"

Expected Output String -

*QUESTION 270 *CODES 4705L996 *RANDOM *MULTI *MIN 1 *VAR “BARRIERS_TO_ATTENDENCE” *PROPERTIES “DIMVAR=BARRIERS_TO_ATTENDENCE” *IF [#Q180,1] UIOPTIONS "? ROWPICKER"
Martin Brisiak
  • 2,957
  • 12
  • 32
  • 48
SonuD
  • 45
  • 5

1 Answers1

0
\*LABEL\s?“([^”])*”

The above regex will match any occurrence of *LABEL followed by an optional whitespace, then your opening character and anything except your closing character, ”, and finally the closing character, ”.

If you need to remove the space after the label-flag, you can extend the regex like so:

\*LABEL\s?“([^”])*”\s?

NOTE, the capture group (marked by the parenthesis) is optional and can be reduced to \*LABEL\s?“[^”]*”\s?.

  • Yes, I needed to remove the additional space as well after label-flag, hence tried with the 2nd pattern that you shared - \*LABEL\s?"[^"]*"\s? It is working fine. Thanks a lot for the quick help.. really appreciate!! – SonuD Jan 12 '21 at 09:05