Extract only the First set of numbers in a String - regex

I have a string like below:
input = Test_8234_and_2345_end
REG_EXTRACT(input,'(\d+)',1)
I'm trying to create a regex that targets only the first set of numbers (i.e 8234) in the above string but it it returns none. what is wrong with my above code.

I'm not familiar with Informatica, but the following Regex pattern should work if you disable the greedy global modifier for the pattern:
(?<=_)[0-9]*
I used the regex101.com online regex calculator to test the pattern and it worked with Python.

Related

Regex match last substring among same substrings in the string

For example we have a string:
asd/asd/asd/asd/1#s_
I need to match this part: /asd/1#s_ or asd/1#s_
How is it possible to do with plain regex?
I've tried negative lookahead like this
But it didn't work
\/(?:.(?!\/))?(asd)(\/(([\W\d\w]){1,})|)$
it matches this '/asd/asd/asd/asd/asd/asd/1#s_'
from this 'prefix/asd/asd/asd/asd/asd/asd/1#s_'
and I need to match '/asd/1#s_' without all preceding /asd/'s
Match should work with plain regex
Without any helper functions of any programming language
https://regexr.com/
I use this site to check if regex matches or not
here's the possible strings:
prefix/asd/asd/asd/1#s
prefix/asd/asd/asd/1s#
prefix/asd/asd/asd/s1#
prefix/asd/asd/asd/s#1
prefix/asd/asd/asd/#1s
prefix/asd/asd/asd/#s1
and asd part could be replaced with any word like
prefix/a1sd/a1sd/a1sd/1#s
prefix/a1sd/a1sd/a1sd/1s#
...
So I need to match last repeating part with everything to the right
And everything to the right could be character, not character, digit, in any order
A more complicated string example:
prefix/a1sd/a1sd/a1sd/1s#/ds/dsse/a1sd/22$$#!/123/321/asd
this should match that part:
/a1sd/22$$#!/123/321/asd
Try this one. This works in python.
import re
reg = re.compile(r"\/[a-z]{1,}\/\d+[#a-z_]{1,}")
s = "asd/asd/asd/asd/1#s_"
print(reg.findall(s))
# ['/asd/1#s_']
Update:
Since the question lacks clarity, this only works with the given order and hence, I suppose any other combination simply fails.
Edits:
New Regex
reg = r"\/\w+(\/\w*\d+\W*)*(\/\d+\w*\W*)*(\/\d+\W*\w*)*(\/\w*\W*\d+)*(\/\W*\d+\w*)*(\/\W*\w*\d+)*$"

regex to find a substring with key value pair

I want a regex for below scenario:
Input String:
"/eve/?tr=abcd&ay=123&test=123456789&e=event"
Output of regex should be (Search for attribute "test" and get the value against it: 123456789
I am using regex: [/test=([^\"]*)/, 1] but it returns string "123456789&e=event"
How to correct this regex?
You need to match everything up to the next &, not ":
[/test=([^&]*)/, 1]
Regexes aren't a magic wand that you wave at every programming problem that involves strings.
What language are you doing this in? Try to use existing tools instead of parsing your own with regexes. If you're using PHP, for example, use the parse_url function and then use explode to break apart the query string on = and &.
Try this regex !
You can extract anything before & .
&test=([^&]*)
I am also attach the output of the regex , you can verify it .

Exclude words with numbers from spellcheck in vim

Following a similar answer I would like to ignore words with numbers that are of the following format:
AB12
AB2
CD98
..
this is achieved with use of the following regex:
[A-Z]{2}\d{1,}
(regex101)
The syntax I'm trying:
:syn match ignoredCapitalWords +[A-Z]{2}\d{1,}+ contains=#NoSpell
does not seem to be generating the desired results as the words remain marked as potentially misspelled:
How can I correctly used the previously generated regex to exclude the desired patterns from regex?
Php regex engine is not vim regex engine. When you doubt your syntax pattern is right just create a new buffer with desired contents and then use / command. The given pattern throws an error, you just have to escape each { character with backslash. So, the correct pattern is: [A-Z]\{2}\d\{1,}. Never used #NoSpell but the pattern works.

vb.net RegEx replace

I have a regex that searches an input string looking for a possible SSN. That part all works great, but I want to be able to replace what I detect as a SSN with a string of asterisks.
For example, if 123456789 is my SSN to replace and I use "123456789, 00123456789000, 1234567899999" as the input string, I just want to end up with "*********, 00123456789000, 1234567899999" but everything I am trying is affecting the second and third string elements as well.
I was thinking that I could use my initial search pattern as the same replace pattern but also make sure there wasn't a digit on each side of it but I can't get it to work.
This is my search pattern and it works fine:
Dim reg As New Regex("\d{3}\D{0,1}\d{2}\D{0,1}\d{4,}")
You can make sure there are word boundaries before and after the pattern using \b...
"\b\d{3}\D{0,1}\d{2}\D{0,1}\d{4}\b"

Using Regular Expression on Live Validation

I'm using LiveValidation (http://livevalidation.com/) to validate a form on my site in the client-side part.
However i'm having problems using the regular expressions:
the example on the website is not very clear and i'm trying to validate a field where i don't want to reject numbers with this:
var f1a = new LiveValidation('nome');
f1a.add( Validate.Format, { pattern: /[a-zA-Z]/i } );
or at least all non digit characters:
[^0-9] ???
are my regular expressions wrong?
or am i using wrongly the live validation with reg exp?
Thanks!
This regex matches input that is all alphabets.
/^[a-z]+$/i
The + is necessary for it to match multiple characters. Without it, the regex matches the first character and stops.
I recommend this website. It has a lot of samples and you can test the regex.
the i in the regex is the ignoreCase flag. When specified, matches are made irrespective of case.