A bit of regex help needed
Re: A bit of regex help needed
The solution to everything:
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: 10
- Joined: 17 Mar 2014 14:40
Re: A bit of regex help needed
Hi, dear members!
Could someone please help me with regex?
Input:
FixedPart Variable1 Variable2.ext
Output:
FixedPart-Variable1Variable2.ext
Replace first space with - and trim second space.
TIA
Could someone please help me with regex?
Input:
FixedPart Variable1 Variable2.ext
Output:
FixedPart-Variable1Variable2.ext
Replace first space with - and trim second space.
TIA
Re: A bit of regex help needed
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 10
- Joined: 17 Mar 2014 14:40
Re: A bit of regex help needed
highend, thank you. It works
And how to make a more universal exp?
Input:
FixedPart Variable1.ext
FixedPart Variable1 Variable2.ext
FixedPart Variable1 Variable2 Variable3.ext
Output:
FixedPart-Variable1.ext
FixedPart-Variable1Variable2.ext
FixedPart-Variable1Variable2Variable3.ext
Replace first space with - and trim other spaces.
And how to make a more universal exp?
Input:
FixedPart Variable1.ext
FixedPart Variable1 Variable2.ext
FixedPart Variable1 Variable2 Variable3.ext
Output:
FixedPart-Variable1.ext
FixedPart-Variable1Variable2.ext
FixedPart-Variable1Variable2Variable3.ext
Replace first space with - and trim other spaces.
Re: A bit of regex help needed
In one turn? Sorry, don't know and no time to think about.
Just use a simple script:
Reminder for myself: Coding is often faster than spending too much time on thinking about the problem...
All SELECTED files will be renamed according to your (last) wish.
Just use a simple script:
Code: Select all
foreach($item, <get SelectedItemsNames |>, "|") {
renameitem(regexreplace(regexreplace($item, "(^.*?)\s", "$1-"), "\s"), $item, "3");
}
All SELECTED files will be renamed according to your (last) wish.
One of my scripts helped you out? Please donate via Paypal
Re: A bit of regex help needed
From the tags.dat file, I am trying to read this
Read Filename and Extra Tag 4 for all those entries which has the tag Images
$data = RegExMatches ("$data", "(.+)\|0+\|.*Images.*\|.*\|.*\|(.*)\|.*\|", <crlf>) ;
The containers in this store this data however, RegExMatches returns the whole row.
$data = RegExReplace ("$data", "(.+)\|0+\|.*Images.*\|.*\|.*\|(.*)\|.*\|", "$1|$2") ;
If I try RegExRepalce, it returns the header data as well as well as files without Images tag.
Combination of both gives the desired output. Any better way to do this
Read Filename and Extra Tag 4 for all those entries which has the tag Images
$data = RegExMatches ("$data", "(.+)\|0+\|.*Images.*\|.*\|.*\|(.*)\|.*\|", <crlf>) ;
The containers in this store this data however, RegExMatches returns the whole row.
$data = RegExReplace ("$data", "(.+)\|0+\|.*Images.*\|.*\|.*\|(.*)\|.*\|", "$1|$2") ;
If I try RegExRepalce, it returns the header data as well as well as files without Images tag.
Combination of both gives the desired output. Any better way to do this
Re: A bit of regex help needed
You shouldn't use needy matches only if really needed.
Apart from that regexmatches isn't able to capture specific parts via backreferences!
Imho you still have to combine them...
Apart from that regexmatches isn't able to capture specific parts via backreferences!
Imho you still have to combine them...
Code: Select all
text regexreplace(regexmatches(readfile("<xydata>\tag.dat"), "^[A-Z]:.*?\|0+\|.*?images.*?$", "<crlf>"), "^([A-Z]:.*?)\|0+\|.*?\|.*?\|.*?\|.*?\|(.*?)\|", "$1|$2");
One of my scripts helped you out? Please donate via Paypal
Re: A bit of regex help needed
Thanks highend
Didn't knew that ? is used for lazy method.
Didn't knew that ? is used for lazy method.
Re: A bit of regex help needed
Don't know what you mean.
Logical or is build with "|"
So a normal pattern looks like
"(one|two|three)"
Logical or is build with "|"
So a normal pattern looks like
"(one|two|three)"
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
Help on regexreplace, please.
These are samples:
AaaaaB - B must go
Aaaaa/AB2 - /AB2 must go
AaaaBCD/1AB2 - BCD/1AB2 must go
IOW, preserve everything before "/" BUT all the immediate left upper cased letters.
How?
These are samples:
AaaaaB - B must go
Aaaaa/AB2 - /AB2 must go
AaaaBCD/1AB2 - BCD/1AB2 must go
IOW, preserve everything before "/" BUT all the immediate left upper cased letters.
How?
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
$test = <<<>>>
AaaaaB
Aaaaa/AB2
AaaaBCD/1AB2
>>>;
$result = "";
$pattern = "^([A-Z][a-z]+)(/|[A-Z])(.*)$";
foreach($item, $test, "<crlf>") {
$result = $result . "Source: $item<crlf>Result: " . regexreplace($item, $pattern, "$1", 1) . "<crlf 2>";
}
text $result;
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
Hello, highend.
Thanks much!
Thanks much!
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
Tried many variations but couldn't find a way to match the opposite way, this time with EXACT matches
/AAaaaa - aaaa
/AB2aaaa2 - aaaa2
/1ABaaaaBCD - aaaBCD
/AAB1aaaBCD - aaaBCD
-in this case, I'll have a line specifying that "AA", another line for "AB2", another for "/1ABa" (yes, a lower case there) and another for "/AAB1"- all these strings must go.
They appear like
/AAaaaa/AB2aaaa2
and will be output'ed like
aaaa
aaaa2
Thanks in advance.
/AAaaaa - aaaa
/AB2aaaa2 - aaaa2
/1ABaaaaBCD - aaaBCD
/AAB1aaaBCD - aaaBCD
-in this case, I'll have a line specifying that "AA", another line for "AB2", another for "/1ABa" (yes, a lower case there) and another for "/AAB1"- all these strings must go.
They appear like
/AAaaaa/AB2aaaa2
and will be output'ed like
aaaa
aaaa2
Thanks in advance.
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
You can't catch
/1ABaaaaBCD - aaaBCD
with the same pattern you'd catch the other three ones... At least I don't see any logic behind it (no explicit number of characters to catch / delete).
Or does it follow the logic:
If a line begins with "/<a digit>" than capture the first 5 (including the "/") characters instead of only the first 4?
/1ABaaaaBCD - aaaBCD
with the same pattern you'd catch the other three ones... At least I don't see any logic behind it (no explicit number of characters to catch / delete).
Or does it follow the logic:
If a line begins with "/<a digit>" than capture the first 5 (including the "/") characters instead of only the first 4?
One of my scripts helped you out? Please donate via Paypal