Replacing line content and newline [closed] - regex

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
If I'd line to replace, for instance:
%bozo%
lol
With:
is_a_clown
lol
What sort of approach should I take? I'd expect a regex substitution with s would be the way to go, but I'm unsure whether there's a better/doable approach.

What sort of approach should I take?
The substitution operator s///, See Substitutions with s///
Perl's substitute operator lets you replace a Regular Expression with another string within a target string.
my $str = "foo";
$str =~ s/foo/bar/;
# $str is now 'bar'
See perldoc perlre (Perl regular expressions) for the various modifiers also.

Related

How do I strip leading section of this string in perl [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have the following string:
[BN_D]hostName=localhost
How do I strip [BN_D] from the string using perl? This would give me the string:
hostName=localHost
You can just do:
^[^]]*.(.*)$
for that
I would use this regex ^\[\w+\] since \w+ matches [A-Za-z0-9_].
...
my $str = "[BN_D]hostName=localhost";
$str =~ s|^\[\w+\]||;
print $str;
...
output
hostName=localhost
You could replace the [...] part with nothing:
'[BN_D]hostName=localhost' =~ s/\[.*?\]//r

Regex For Simple Pattern Matching [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How would one create a regex for a string containing alphanumeric characters to match everything including and after the first occurrence of a numeric character?
example
HdeTT55679HHdsdd
would match
55679HHdsdd
and
re678TTHY88
would match
678TTHY88
thanks in advance
[0-9].*
this will match anything after a number
If you are sure that the string only contains alnum characters, then you can simply match
[0-9].*
If not, use
[0-9][A-Za-z0-9]*
use this regular expression \d.+
If you're using PCRE, the following might work for you:
'[^\d]*\K.*'
For example:
$ echo HdeTT55679HHdsdd | grep -oP '[^\d]*\K.*'
55679HHdsdd
$ echo re678TTHY88 | grep -oP '[^\d]*\K.*'
678TTHY88

Matching a certain word that is not surrounded by quotationmarks with regex [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
At first I thought it would be very trivial to do this with regex, but it turns out, I'm wrong.
I can't seem to find a simple and reliable way of doing this with regex, so I'm putting it out there:
I want to match every instance of FOO that is not surrounded by quotations i.e:
FOO
xFOO
FOOy
"FOO
FOO"
but not "FOO"
In other words, I want to find FOO, but only if it's not in quotes.
I hope this makes sense. :-)
Use lookarounds in your regex:
(?:(?<!")FOO|FOO(?!"))
$s = 'FOO"';
if (preg_match('/(?:(?<!")FOO|FOO(?!"))/', $s, $m))
print_r($m);
This will match FOO it is not followed by " OR match FOO if it not preceded by "
In other words it will NOT match FOO only when FOO is enclosed in double quotes.
LIVE DEMO: http://ideone.com/kL3I3M
You can try this pattern:
"FOO"(*SKIP)(?!)|FOO
(since debuggex doesn't have a full support of pcre, you can test it with http://regex.larsolavtorvik.com/ or with http://www.phpliveregex.com/ or http://regexp.zug.fr/)

regex match anything between {esbmsg:header:xxxxxx} [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
How to match anything between {esbmsg:header: and }
like xxxxxx could be any string {esbmsg:header:xxxxxx}
Try with:
{esbmsg:header:([^}]*)}
Where [^}]* matches everything that is not } character.
Try this regex
{esbmsg:header:(.*)}
It will also allow you to have any character in value.
Well, if you want to capture only the content of your expression (the "xxxxx" part) the best approach is to use positive look ahead:
(?<={esbmsg:header:)[^}]+
Depending on how your content looks you might have to tweak the [^}] part. For further information on regex (or a detailed explanation of the expression above) I recommend the following:
Regex reference
Regex tutorial

regular expression to match the same character being typed with different style [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm looking for a simple regular expression to match the same character being typed with different style, like : احمد - أحمد إحمد - آحمد
the word has a char that could be typed in different form.
thank you in advance.
You can use the following expression to match: احمد - أحمد إحمد - آحمد
/[\x{627}\x{625}\x{623}\x{622}]\x{062D}\x{0645}\x{062F}/u
I assumed you are using PCRE flavor, if you are using a different flavor then you should look how to specify Unicode code points using your flavor and what modifiers you need to pass the regular expression engine so it can deal with Unicode.
Regex 101 Demo