having trouble with Square Brackets

A swapping-ground for Regular Expression syntax

having trouble with Square Brackets

Postby Rigas » Tue Jun 02, 2015 4:39 pm

I'm very close to what I need, just having a little trouble with Square Brackets

What I have it a lot of folders with names and dates that I need organised a bit better
my folders names are like this

[website.com] [Category] Name of Project [People Assigned] Date

example

[website.com][Events] In Bloom [Mary] 07 June 2015

What I have is
Match
(\[.*\])(\s+)(\[.*\])(\s+)(.*\[)(.*\])(.*)

Replace:
\6 - \5 - \1 \3 \7

But I what I get it

Mary] - In Bloom [ - [website.com] [Events] 07 June 2015

I cant see what is causing the People to keep that extra Square Bracket ] and title "In Bloom" to have the opening square bracket[

I'm sure its something simple, but its just giving my trouble.


Any help you give is appreciated.
Rigas
 
Posts: 1
Joined: Tue Jun 02, 2015 4:29 pm

Re: having trouble with Square Brackets

Postby Stefan » Wed Jun 03, 2015 10:53 am

I have not tested, but you may want to check out the '?' non-greedy operator.

Use like (\[.*?\])


 
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Match Square Brackets in name - reorder swap rearrange

Postby Stefan » Wed Jun 03, 2015 11:18 am

 
No, I had to redo the whole matching expression,

(as e.g. your \s+ expression do not match anyway on your provided example,
also you have integrated the brackets into the capturing groups (\[word\]) >>> [word], instead of \[(word)\] >>> word)

like (depending on your in real wanted result, which is totally unclear to me, based on your post)


FROM/Before/Current:
[website.com][Events] In Bloom [Mary] 07 June 2015

TO/After/Wanted:
Mary - In Bloom - website.com Events 07 June 2015

----------------------------------------------------------------------------------------------------------
Rule
Wanted MATCH:
(split your issue into tasks)
Code: Select all
[website.com] >>>    \[(.*?)\]\s*       >>>>> as capture \1
[Events]      >>>    \[(.*?)\]\s*       >>>>> as capture \2
In Bloom      >>>    (.*?)\s*           >>>>> as capture \3
[Mary]        >>>    \[(.*?)\]\s*       >>>>> as capture \4
07 June 2015  >>>    (\d+ \w+ \d{4})    >>>>> as capture \5


REPLACE in new order: \4 \3 \1 \2 \5
----------------------------------------------------------------------------------------------------------

So for your provide example name,

USE:
RegEx(1)
Match: ^\[(.*?)\]\s*\[(.*?)\]\s*(.*?)\s*\[(.*?)\]\s*(\d+ \w+ \d{4})$
Replace: \4 - \3 - \1 \2 \5



- - -
Next time, please provide Before/After examples.
 
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions