-1

Input:

:CITYNAMEONE SCHEDULED
:CITY NAME TWO
:CITYNAMETHREE

Tried:

:([A-Z\s]+)(?=SCHEDULED)
:([A-Z\s]+)(?:SCHEDULED)?

Expecting:

CITYNAMEONE
CITY NAME TWO
CITYNAMETHREE
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
ck1mark
  • 3
  • 2

2 Answers2

0

You can use

:(.*?)(?=\s*SCHEDULED|$)

See the regex demo.

Details:

  • : - a colon
  • (.*?) - Group 1: zero or more chars other than line break chars as few as possible
  • (?=\s*SCHEDULED|$) - a positive lookahead that requires zero or more whitespaces or end of string immediately to the right of the current location.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
0

To keep the capital letter genre and to consume only words that are not SCHEDULE this is ideal

:(?:\s*(?!SCHEDULED)[A-Z]+)+

https://regex101.com/r/3GefdG/1

: 
(?:
  \s* 
  (?! SCHEDULED )
  [A-Z]+ 
)+

If need to trim white space at the beginning as well, , a capture group is needed.

:\s*((?!SCHEDULED)[A-Z]+(?:\s*(?!SCHEDULED)[A-Z]+)*)

https://regex101.com/r/dmcXpQ/1

: 
\s* 
(                     # (1 start)
  (?! SCHEDULED )
  [A-Z]+ 
  (?:
    \s* 
    (?! SCHEDULED )
    [A-Z]+ 
  )*
)                     # (1 end)
sln
  • 2,071
  • 1
  • 3
  • 11
  • Well done. Thank you for the Capture Group example. As of today I don’t understand the amount of code required for the capture group version to work. – ck1mark Jan 24 '23 at 21:34