Suppose I have a field like this: a1234
Is there a way to grab all the letters that are immediately followed by numbers? I know I can substr the first position but I want be able to work with this for example too: abc1234
.
Ty in advance
I'm not clear about what you want to accomplish, but I think the rex command will do what you want. This command will extract the letters from a field containing letters followed by numbers and put them in a field called 'letters'.
... | rex field=foo "(?<letters>[a-zA-Z]+)\d+" | ...
I'm not clear about what you want to accomplish, but I think the rex command will do what you want. This command will extract the letters from a field containing letters followed by numbers and put them in a field called 'letters'.
... | rex field=foo "(?<letters>[a-zA-Z]+)\d+" | ...
Thank you for this. What if I want to specify letters or a combination of letters and numbers that follow numbers?
For letters that follow numbers:
"(?<foo>\d+)[a-zA-Z]+"
For letters and number following numbers:
"(?<foo>\d+)[a-zA-Z0-9]+"
regex101.com is a great site for experimenting with regular expressions.
This is really helpful ty!
Then you modify the bracket expression: [a-zA-Z]
which currently says "Match a single character that is either a to z, or A to Z" For example if you wanted only to match one of the lower case versions of the letters that Vanna White gives you for free in the bonus round: [rstlne]
(The plus sign after this expression says instead of just one, I want one or more, as many times as I can up front)
There is a lot of nuances to crafting regular expressions for example, if a digit is one of the characters you want to match and also ensure is following... depending on requirements may not be possible, or may involve lookahead and lookbehind expressions, I would recommend taking some of your example data and playing with a online tester such as https://regex101.com/ or if you want some practice at building regular expressions play some regex golf: http://regex.alf.nu/