Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex: switch words position in notepad++

I have text in the following pattern:

1 NAME word1 word2 wordn /words/
...
...
1 NAME word1 word2 wordn /words/

And I need a regex that will reorder it to:

1 NAME /words/ word1 word2 wordn
...
...
1 NAME /words/ word1 word2 wordn

I am trying to do this in notepad++ but can't figure out the regex to match n number of words until the character /

Please help!

like image 846
user1712904 Avatar asked Jan 16 '23 10:01

user1712904


2 Answers

Find: ([^ ]+) ([^/]+)/([^/]+)/

  • ([^ ]+) Matches "name" as anything but a space into group \1 (followed by a space)
  • ([^/]+) Matches "all words" as anything up until the first / into group \2
  • /([^/]+)/ Matches anything between / and / into group \3

Replace With: /\3/ \2\1

like image 125
TomFuertes Avatar answered Jan 31 '23 11:01

TomFuertes


Try

(?<=1 NAME )(\S+ ){n}/words/
like image 35
Bergi Avatar answered Jan 31 '23 11:01

Bergi