goldwing
goldwing

Reputation: 45

Regex to find all spaces in lines beginning with a specific string

I am searching for a regex to find all the spaces in lines starting with a specific string (in a SVN dump file). Despite the "global" modifier my regex returns only the first occurence of the space character.

A part of the file i am working on :

...
pla bla bli

Node-path: branches/BU ILD/ml_cf/syst em/Translation/TranslationManager.class.php  
Node-kind: file
Node-action: change
Text-delta: true
....

The regex :

/Node-path: \S*(\ )/g

finds only the first space (between U and I) but not the others on the line.

Upvotes: 2

Views: 314

Answers (1)

anubhava
anubhava

Reputation: 784958

Using PCRE regex to find all the spaces on a line starting with a particular text, use this regex:

/(?:^Node-path: |\G)\S+\K\h+/gm

RegEx Demo

  • Using (?:Node-path: |\G) we are matching lines starting with Node-path: OR positioning at the end of the previous match.
  • \G asserts position at the end of the previous match or the start of the string for the first match
  • \K resets the starting point of the reported match.
  • \h+ matches 1 or more of horizontal whitespace (space or tab)

Upvotes: 1

Related Questions