A bit of regex help needed
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: A bit of regex help needed
For
Start: "(NEXT 5 (good)"
End: "Closing Times"
I need to remove everything that's between 'start' and 'end', including 'start' and 'end'.
$a = regexreplace("<clipboard>", "\(NEXT 5 (good)\).*?\(Closing Times\)", ""); echo $a;
Is not working.
Any help here, please?
Start: "(NEXT 5 (good)"
End: "Closing Times"
I need to remove everything that's between 'start' and 'end', including 'start' and 'end'.
$a = regexreplace("<clipboard>", "\(NEXT 5 (good)\).*?\(Closing Times\)", ""); echo $a;
Is not working.
Any help here, please?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Re: A bit of regex help needed
Code: Select all
$c = <<<>>>
(NEXT 5 (good)
This is one sentence.
Ok, another one...
(Closing Times)
>>>;
$a = regexreplace($c, "\(NEXT 5 \(good\)[\s\S]*?\(Closing Times\)", ""); echo $a;
Code: Select all
"\(NEXT 5 (good)\)
You've created a reference group only for "good". The parenthesis must be escaped.
And the "\)" => There is no (second) closing parenthesis in your clipboard after "good)"...
My regex works for text with and without line breaks.
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: A bit of regex help needed
"Closing Times" has no parenthesis, so I finally discovered that this was preventing the actual job to work properly.
should do as per your code but it's not. How do I fix it?
Code: Select all
$c = <<<>>>
This will be kept!
(NEXT 5 (good)
This is one sentence.
Ok, another one...
Closing Times
...this will remain too!
>>>;
$a = regexreplace($c, "\(NEXT 5 \(good\)[\s\S]*?\Closing Times\r\n[\s\S]", ""); echo $a;
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Re: A bit of regex help needed
Because you have a backslash, that doesn't belong there.
Code: Select all
\Closing
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: A bit of regex help needed
Parfait!
Thank you, highend!
Thank you, highend!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: A bit of regex help needed
Guys,
I need to fix indentation for .xys files.
Is this safe? (please see the comment-question on the code, too)
Thanks in advance.
I need to fix indentation for .xys files.
Is this safe? (please see the comment-question on the code, too)
Code: Select all
$re = regexreplace("$re", '\r\n"', '"'); //just in case
$re = regexreplace("$re", '(\r\n)([0-9])', '$2');
$re = regexreplace("$re", '(\r\n)([a-zA-Z])', '$2');
$re = regexreplace("$re", '(\r\n)([\s\S])', '$2'); // is this valid for SYMBOLS, ie, non-numbers && non-letters?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Re: A bit of regex help needed
No, it's not. [\s\S] is like a dot that matches new lines too. Try
EDIT: ok, maybe I got it wrong. What do you want to match exactly?
Code: Select all
\W
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Don sees all [cit. from viewtopic.php?p=124094#p124094]
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: A bit of regex help needed
I want to match stuff like
pseudo"123
"this;
-making
pseudo"123"this;
pseudo"123
abc"this;
-making
pseudo"123abc"this;
pseudo"
123"this;
-making
pseudo"123"this;
pseudo"
&123"this;
-making
pseudo"&123"this;
Thanks, Marco.
pseudo"123
"this;
-making
pseudo"123"this;
pseudo"123
abc"this;
-making
pseudo"123abc"this;
pseudo"
123"this;
-making
pseudo"123"this;
pseudo"
&123"this;
-making
pseudo"&123"this;
Thanks, Marco.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Re: A bit of regex help needed
How many \r\n are there between two quotes?
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Don sees all [cit. from viewtopic.php?p=124094#p124094]
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: A bit of regex help needed
A single <crlf> separating the two lines that may join into one.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Re: A bit of regex help needed
Code: Select all
"(.*?)\r\n(.*?)"
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Don sees all [cit. from viewtopic.php?p=124094#p124094]
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: A bit of regex help needed
$re = regexreplace("$re", '\r\n"', '"');
$re = regexreplace("$re", '(\r\n)([a-zA-Z0-9])', '$2');
$re = regexreplace("$re", '(\r\n)([^0-9a-zA-Z\s])', '$2');
Your code is matching everything as it seems, so in a regexreplace all is gone. Those codes I'm using are doing the job. Anything potentially harmful on them? Now that you may have a clearer picture, any elegant solution?
$re = regexreplace("$re", '(\r\n)([a-zA-Z0-9])', '$2');
$re = regexreplace("$re", '(\r\n)([^0-9a-zA-Z\s])', '$2');
Your code is matching everything as it seems, so in a regexreplace all is gone. Those codes I'm using are doing the job. Anything potentially harmful on them? Now that you may have a clearer picture, any elegant solution?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Re: A bit of regex help needed
It shouldn't match everything, only the text between two quotes. Tested it in a text editor with your test cases and it worked perfectly
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Re: A bit of regex help needed
Lol I'm an idiot, I gave you the matching but not the replacement
Input:
Output:
Code: Select all
$re = regexreplace("$re", '"(.*?)\r\n(.*?)"', '"$1$2"');
Code: Select all
$re =<<<QWERTYUIOP
pseudo"123
"this;
pseudo"123
abc"this;
pseudo"
123"this;
pseudo"
&123"this;
QWERTYUIOP;
$re = regexreplace("$re", '"(.*?)\r\n(.*?)"', '"$1$2"');
text $re;
Code: Select all
pseudo"123"this;
pseudo"123abc"this;
pseudo"123"this;
pseudo"&123"this;
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
Don sees all [cit. from viewtopic.php?p=124094#p124094]
-
- Posts: 2341
- Joined: 04 Jan 2010 14:27
- Location: Pasárgada (eu vou!)
Re: A bit of regex help needed
No, Marco - I AM the idiot here as I DID used the "$1$2" (also $1, also $2, also "" and so on...) and got nothing.
Strange.
Anyway, now it's working and I'll stick to your solution as it seems more reliable. Hey, total regex-n00b here! (Last year I tried to get some regex lessons but life had another turn on me = pending!)
Many thanks.
Strange.
Anyway, now it's working and I'll stick to your solution as it seems more reliable. Hey, total regex-n00b here! (Last year I tried to get some regex lessons but life had another turn on me = pending!)
Many thanks.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...