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

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

Related

How do you extract all zip codes except a zip code? [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 9 years ago.
Improve this question
I would like to extract all zip codes except 55802 from a text file.
\d\d\d\d\d && ^55802
I tried to use the regular expression above, but it isn't working.
What should I change?
How about
(?!55802)\d{5}
That should match 5 digits (\d{5}) except where the text matches (55802) (?!55802 is a negative lookahead)
Generally speaking, it's best to check on the outside.
$zip =~ /^\d{5}\z/ && $zip ne '55802'
or die("Not a valid zip code\n");

regex to validate string of 10 characters which are all digits [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 9 years ago.
Improve this question
I want to match a string of 10 characters and all of them need to be integers. How do I write a regular expression to check for this format.
Valid values should be something like - '1234567890', '4321567890'
The easiest (not all dialects support this):
[0-9]{10}
Another option:
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
If you match the whole string, don't forget the ^ and $ markers:
^[0-9]{10}$

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

Extract the email address, and replacing a character using 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
I am trying to come up with Reg ex expression that would match an email address starting with format E- and replacing the "AT" with an actual "#" sign.
Here is an example:
E-CANAD.JACK AT EXAMPLE.COM.
The desired output will need to look like CANAD.JACK#EXAMPLE.COM.
Replace:
[eE]-([a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*) (?:at|AT) ([a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*[.][a-zA-Z]+)
By:
$1#$2
More:
Visualization by
Debuggex
Demo by RegExr
You didn't mention your language, so I'm assuming perl
s/^E-(.*) AT (.*)$/$1\#$2/;

Replacing line content and newline [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
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.