Regex in Yahoo Pipes: append only if match found - regex

In Yahoo Pipes, I'm trying to append content to existing string, but only if a match is found in that string.
Specifically, I want to append "#Fracking" to the end of the line, but only if "Hydraulic Fracturing" is found in the item.title.
My regex is as follows (doesn't work): replace (?(Hydraulic Fracturing)(.*)) with $1 $#Fracking
What am I doing wrong? Does Yahoo Pipes not support conditional regex? I could not find an answer to that.
Thanks for any help!

If I understood correctly, you could do like this:
pattern: .*Hydraulic Fracturing.*
replacement: $0#Fracking
It seems that in Yahoo Pipes the matched string can be back referenced with $0.
Here, the .* in the front and back make the entire string match if it contains "Hydraulic Fracturing", and then replace the whole thing with itself, plus "#Fracking" appended. If the string doesn't contain "Hydraulic Fracturing" then there will be no replacement.

Related

Notepad++ RegEX how do I append a character based on start of the character and before a character?

I would like to append _OLD to the end of each strings that starts with SR_ but before the symbol ' or without it
For example my text is the following:
SR_Apple
When the 'SR_APPLE' rotten, we must discard it.
I would like the find and replace to do:
SR_Apple_OLD
When the 'SR_APPLE_OLD' rotten, we must discard it.
I have tried (SR_*)+$.*(?='\s) based on what i Learned but no luck so far. Please help. Thx in Adv
For simple cases you should be able to use
Find: (\bSR_[\w]+)
Replace: $1_OLD
(\bSR_.+?)('|$) and $1_OLD$2 could also work if the text after SR_ is more complex
The lookbehind you're using is only matching the string if it ends with a ' so it won't find the text not in quotes.
regex101 is a useful tool for debugging expressions

Use regex to strip out emails

I know that this is a notoriously difficult topic. The best regex that I've found after trawling many different answers is the one at http://emailregex.com/
It works great at validating an email address, but I'm struggling to alter this regex to find all email addresses in a string.
I'm using the PHP version of the regex.
How would I go about using this regex to find all of the email addresses in a string?
I know about the preg functions, my PHP code isn't as much the problem as adapting that regex.
$redacted = preg_replace_callback(
"/$emailRegex/i",
function ($matches) {
return '[' . $this->getHashedValue($matches[0]) . ']';
},
$input
);
If you already have a working regular expression, you can use PHP's preg_replace to replace all (non-overlapping) matches by a certain string, in our case "" (to remove them).
preg_replace($your_regex, "", $your_string)
This should strip all matches from your string.
Also, as #MonkeyZeus commented, if your regex contains the start anchor (^) or the end anchor ($), make sure to remove those before using preg_replace. Otherwise, the only match you can get will be the entire string, if it matches.

Perl, replace multiple matches in string

So, i'm parsing an XML, and got a problem. XML has objects containing script, which looks about that:
return [
['measurement' : org.apache.commons.io.FileUtils.readFileToByteArray(new File('tab_2_1.png')),
'kpi' : org.apache.commons.io.FileUtils.readFileToByteArray(new File('tab_2_2.png'))]]
I need to replace all filenames, saving file format, every entry of regexp template, because string can look like that:
['measurement' : org.apache.commons.io.FileUtils.readFileToByteArray(new File('tab_2_1.png'))('tab_2_1.png'))('tab_2_1.png')),
and i still need to replace all image_name before .png
I used this regexp : .*\(\'(.*)\.png\'\),
but it catches only last match in line before \n, not in whole string.
Can you help me with correcting this regexp?
The problem is that .* is greedy: it matches everything it can. So .*x matches all up to the very last x in the string, even if all that contains xs. You need the non-greedy
s/\('(.*?)\.png/('$replacement.png/g;
where the ? makes .* match up to the first .png. The \(' are needed to suitably delimit the pattern to the filename. This correctly replaces the filenames in the shown examples.
Another way to do this is \('([^.]*)\.png, where [^.] is the negated character class, matching anything that is not a .. With the * quantifier it again matches all up to the first .png
The question doesn't say how exactly you are "parsing an XML" but I dearly hope that it is with libraries like XML::LibXML of XML::Twig. Please do not attempt that with regex. The tool is just not fully adequate for the job, and you'll get to know about it. A lot has been written over years about this, search SO.

Matching from a starting delimiter to an end delimiter (Regex/pattern matching)

I am trying to match for a certain block of text.
The format of the text I want to match is
<pevz:url>https://some.server.com/arbitraryFoo.jpeg</pevz:url>
where only <pevz:url> and </pevz:url> are known.
My naive try was to match with
<pevz:url>*([0-9a-zA-Z:/._-])<\/pevz:url>
but that didn't work. I am using gedit to match with the default search and replace (no advanced-find).
How can I match for the whole string?
Best regards,
Joe Cocker
You can try:
<pevz:url>(.*?)<\/pevz:url>
or
<pevz:url>([^>]+)<\/pevz:url>
Regex Demo

Regex to find the last underscore and all text that follows it

My sample text would be something like this list
alpha123_4rf_Joe
45beta_Frank
Red5Great_Sam_Fun
and I would like to be left with (with a notepad++ regex find and replace)
alpha123_4rf
45beta
Red5Great_Sam
I am just looking for the Regex as I understand notepad++ :-)
Try this one:
_[^_]+$
Replace with an empty string.
To explain it:
_ match a single _ character
[^_]+ match any character that is not a _ character, one or more times (+)
$ match the end of the string
You can use:
/^(.*)(_.*?)$/\1/
Demo
If you are attempting to do this for PromQL label_replace to use for grouping as I was, this will be helpful to you:
[^.*]+_(.*?)$
I know this post is about notepad++ - however this post kept coming up in my searches and I found that the given solutions did not work with PromQLs variant of regex. Adding this answer for future folks landing here for similar reasons.