How to extract numbers and letters from a string Imacros - imacros

For example if I extracted this string 1234hrt-13hfydsfn-12 how could I extract the data so that i could extract the numbers and letters only?

With this code, for example:
SET !EXTRACT EVAL("'{{!EXTRACT}}'.replace(/\W/g, '');")

Related

Regex for values that are in between spaces

I am new to regex and having difficulty obtaining values that are caught in between spaces.
I am trying to get the values "field 1" "abc/def try" from the sameple data below just using regex
Currently im using (^.{18}\s+) to skip the first 18 characters, but am at at loss of how to do grab values with spaces between.
A1234567890 field 1 abc/def try
02021051812 12 test test 12 pass
3333G132021 no test test cancel
any help/pointers will be appreciated.
If this text has fixed-width columns, you can match and trim the column values knowing the amount of chars between start of string and the column text.
For example, this regex will work for the text you posted:
^(.*?)\s*(?<=.{19})(.*?)\s*(?<=^.{34})(.*?)\s*(?<=^.{46})
See the regex demo.
So, Column 2 starts at Position 19, Column 3 starts at Position 34 and Column 4 (end of string here) is at Position 46.
However, this regex is not that efficient, and it would be really great if the data format is fixed on the provider's side.
Given the not knowing if the data is always the same length I created the following, which will provide you with a group per column you might want to use:
^((\s{0,1}\S{1,})*)(\s{2,})((\s{0,1}\S{1,})*)(\s{2,})((\s{0,1}\S{1,})*)
Regex demo

Alteryx - Split a string with an uncertain length into 5 characters per column

I am trying to split a string (the string length is uncertain; it could be 500 characters or 1500 characters) into multiple columns, and each column should only contain 5 characters.
For example,
If column A contains the string:
AAGANAB5ARAB7AAAB9AAAC--CAC--1ACMRD
Then, I need Column B to Column H to be:
AAGAN,
AB5AR,
AB7AA,
AB9AA,
AC--C,
AC--1,
ACMRD
Also, the string contains “-“, but it is NOT delimiter. It should also be counted as a part of 5 char strings.
I know RegEx is probably the function I should use, and just by putting "(.....)" in the Regular Expression, Alteryx can extract the first 5 characters. But I don't know how to ask Alteryx to automatically split the entire string (length varies each row) to columns of 5 chars.
In Alteryx, use their RegEx tool (instead of the Formula tool with one of their REGEX expressions). In the config panel of the RegEx tool, and simply enter ..... as the RegEx, and the key is to select "Split to Rows"... this will give you rows with a new field that is the result of the applied RegEx.

Regular expression to match a string into a text

I've a TXT file and I use a Reg Expr to get the text after a string
"Diagnosis Statement:"
the Full text is :
Diagnosis Statement:
6/28/2011
RZZZCG77T77G355S
Report text is here ....... end of report
I would get only the 16 digits "RZZZCG77T77G355S" into the text
(16 digits mix of numbers and capital letters)
I can get the text after the string "Diagnosis Statement:" with :
(?ms)^Diagnosis Statement\s*:(?<value>.*)
and I get the code with :
^[A-Z0-9]{16}?$
But cannot get the correct way to merge both and get only the 16 digits string from
text after "Diagnosis Statement:"
Can you give some help ?
On your example, ^([A-Z0-9]{16})$ is enough. Test it here.
Do you have another place in the document where you find text with a format of 16 char, with only captials and digits ? If no, this regex is enough.
With the following regex, you can find the first thing you find with the good format, following "Diagnosis Statement:" and one line of random text.
Diagnosis Statement:\s*.*\s*\K^([A-Z0-9]{16})$
Test it here

Regex for only allowing letters, numbers, and commas?

I have a label name called "Color Scheme" and an input showing you the HEX colors that you just inputted.
I have limited the max length to 27 so when they input their HEX colors, like this 222222,000000,999999,ffeb00. By default, I put the commas in myself, but I want the regex to automatically input a comma to the end of the HEX color and only allow letters, numbers, and commas.
Does anyone the regex code for this?
If hex values are always 6 chars long, try this:
^([0-9a-fA-F]{6}(,|$)){4}
See live demo.

.net regex specifing number of digits in a string

hello i am trying to find a match in the followig format in a text file using regex and save the number into a variable.
id='12341234321234131313'
now my problem i want to consider the string a match only if the integer has a number digits between 16 and 22, is it possible to do this directly using regex or do i have to check for the length?
i would use the following if to match when the number of digits is 20
Dim rex = New Regex("id='(\d{20})'")
but what about between 2 numbers?
To check for a range of repeat lengths, use {min,max}:
"cid='(\d{16,22})'"