Regular expression to match a string into a text - regex

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

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

Regex - Alteryx - Parse - How to find an expression starting by the end of the string

I need to parse the following expression:
Fertilizer abc 7-15-15 5KG BOX 250 KG
in 3 fields:
The product description: Fertilizer abc 7-15-15
Size: 250
Size unit: KG
Do not know how to proceed. Please, any help and explanation?
Try this in the alteryx REGEX Tool with Parse selected as the Method:
([A-z ]* [\d-]{6,8}) ([A-Z\d]{2,6}) (.{1,5}?) (\d*) ([A-Z]*)
You can test it at Regexpal to see the breakdown of each group but essentially the first set of brackets will get you your product description (text and spaces until 6-8 characters made up of digits and dashes), the 2nd & 3rd parts will deal with the erroneous info that you don't want, the 4th group will be just digits and the 5th group will be any text afterwards.
Note that this will change dramatically if your data has digits where there is characters currently etc.
You can always break it up into even smaller groups and then concatenate back together as well.

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.

Regex selecting the last 6 numbers of

I am a noob at regex and i've been trying to select 6 numbers from within a file and then replace those 6 numbers with the same numbers plus , new line (making a CSV obviously).
Anyway sample data is simply nonsense like this:
fafksadjlkgtjafglkj210000adsfaklgjadklgjag3600001skfjaklaj093i393593390000002sadfljafkjgakjgasafksadjlkgtjafglkj£94.00 489438adsfaklgjadklgjag7700001skfjaklaj093i393593390000002ssafksa djlkgtjafglkj000000adsfaklgjadklgjag0000001skfj aklaj093i393593£39.00900002ssafksadjlk gtjafglkj000000adsfaklgjadklgjag0000001skfjaklaj093i3935£933.90000002s
Note some of the numbers are attached to currency values as well (and some are next to it but contain a space before hand) but the end will always be 6 numbers (consider them to be random as I can't see a pattern).
So I basically need to select strings matching numerics that are six digits long or longer, if longer then it just uses the last 6 digits.
Then I will replace it with itself and a comma and new line.
I hope that makes sense, i've tried a few things without success..
Thanks, edit the closest I have is:
(\d)\d{6}(?!\d)
In the Find what: text field, type in (\d{6})(\D). In the Replace with: text field, type in $1\r\n$2. Make sure that the regular expression radio button is selected. For your input, that should yield this:
fafksadjlkgtjafglkj210000
adsfaklgjadklgjag3600001
skfjaklaj093i393593390000002
sadfljafkjgakjgasafksadjlkgtjafglkj£94.00 489438
adsfaklgjadklgjag7700001
skfjaklaj093i393593390000002
ssafksa djlkgtjafglkj000000
adsfaklgjadklgjag0000001
skfj aklaj093i393593
£39.00900002
ssafksadjlk gtjafglkj000000
adsfaklgjadklgjag0000001
skfjaklaj093i3935£933.90000002
s
You want
\d{6}(?=\D*$)
Read more about anchors here.
i've been trying to select 6 numbers from within a file and then replace those 6 numbers with the same numbers plus , new line
So you're basically trying to do this, right?:
Find:
(\d{6})(\D)
Replace:
\1\n\2
[Online example]
How about:
Find what: (\d{6,})(?:\D*)$
Replace with: $1,\n

Dreamweaver help needed with regular expression search and replace

I've got a bit of an issue. I have lots of text document I need to copy into html to try and speed the procees up I've been looking into search and replace regular expressions to help me add bold tags to varies bits of text.
I have lots of text like this:
1. Centrum Multimineral Vitamin x 30 £3.19 was £4.79 (11p per tablet)
I'm trying to write a regular expression search and replace to look for all text between a number with a dot and space after it and the first price. I want the find and replace to do this:
<b>1. Centrum Multimineral Vitamin x 30 £3.19</b> was £4.79 (11p per tablet)
So far I've written this expression which kind of works:
search for:
([0-9]{1}[\.\s][\s\D]?[^<]*)(\£\d\.\d\d[^<])
replace with :
<b>$1$2</b>
Output :
<b>1. Centrum Multimineral Vitamin x 30 £3.19 was £4.79</b> (11p per tablet)
How do I alter this search so that it stops at the 1st £ sign and includes the price?
Try this small modification:
([0-9]{1}[\.\s][\s\D]?[^<]*?)(\£\d\.\d\d[^<])
^
I have added ? which makes the asterisk * operator reluctant (lazy) so it reads the input string character by character instead of going all the way to the end, and then backtrack to try to find \£\d\.\d\d[^<].