regex to rearrange string

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Forum Newbie
Posts: 1
Joined: Wed Oct 26, 2016 10:32 am

regex to rearrange string

Post by bennyutzer »

hi there,

i have a basic knowledge of regex, but i came across a problem that exceeded my skills. i have a string like this:

[text][AB] SomeText (26-10-2016)[/text]

and using regex i want to transform it to:

[text][AB] 2016.10.26 - SomeText[/text]

is that possible? what regex command could i use for this?

User avatar
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: regex to rearrange string

Post by requinix »

Regular expressions don't have "commands".

Match each portion of the string that you want to deal with, then put each into the substitution string wherever you want. For example, the search and replace could be

Code: Select all

\[(..)\] (.*?) \((\d\d)-(\d\d)-(\d\d\d\d)\)

Code: Select all

[\1] \5.\4.\3 - \2
The [AB] doesn't change so actually you could just ignore that part.
Post Reply