Regex For Simple Pattern Matching [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
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

Related

How to start a RegEx statement at the 2nd position of a string [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 have a string
.HACK G.U. VOL. 1 REBIRTH
I'm using a tool that allows me to specify a RegEx statement that can be used in a replace operation.
I want the RegEx to find all the periods "." that start after the 1st position. The replace operation should return the following.
.HACK GU VOL 1 REBIRTH
Thanks
The following will do the trick:
(?<!^)(\.)
per http://rubular.com/r/w1apzTZLPk
Since Javascript doesn't support negative lookbehind, this can't be done in Javascript, but there are alternatives as discussed in http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript
One approach in this case would be to capture the previous character and replace it with the same content as part of the replacement process, as in:
(.)(\.)
Note: You don't need to use a capture group for the matching of the literal . in either of the above. I just used that technique to highlight the match in Rubular.

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

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.

Regular Expression to Match both Capital and Lower Characters [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 writing script for screening words within contents and replace it with *, if matched.
I am using the following simple regular expression for screening words like apple, banana
(\bbanana|apple\b)
It match all words banana and apple within content but not Apple or aPPle etc.
I want to write regular expression which match word regardless which character is capital or lower.
If i replace content to lower characters it will solve problem, but i want to keep content in original state.
You can try something like this:-
/[A-Z]{3}([0-9]{1,4})?|[A-Z]{1,3}/i
In your case:-
/\b(banana|apple)\b/i
the /i switch does case-insensitive matching:
/\b(banana|apple)\b/i
I also moved your word boundary markers outside of the alternation.