Here's the string I'm interrogating:
[Card-1 Intake : 30 C] [Card-1 Exhaust : 35 C] [Card-1 CPU : 38 C] [Card-1 Switch CPU : 47 C]
I am completely lost in how I can use regex (PCRE) to grab the 'Intake' value, i.e. 30.
Any help appreciated.
To match just the value, use a look behind:
(?<=Intake : )\S+
See live demo.
If look behinds are not supported, use group 1 of:
Intake : (\S+)
See live demo.
/Card-1 Intake : (\d+) C/
If you do x = string.match with the regex you can access it with x[1]
Related
I need regex to validate a pattern,
pattern can be combination of following list,
yyyy : current year
yy : last 2 digits of current year
MM : current month
dd : current day
HH : current hour
mm : current minute
ss : current second
fff : current milisecond
ff : current 1/100th of second
R : random digits
Rules
Minimum 16 and maximum 20 characters can be allowed.
We should be able to add fix characters only in capitals(e.g. 'yyyyAAddmmss' here AA is fix value)
We should escape a fix character(e.g. \R, then R is not replaced)
Only HMR characters should be allowed to escape like '\H' or '\M' or '\R' as this characters are in the pattern.
Pattern should contains minimum 4 random digits (e.g. yyRMMRddRHHRmmRss)
It should allow digits 0-9
It should not allow special characters.
Example of such valid pattern
yyyyMMddHHmmssff
yyyyMMddHHmmssffR
AByyyyMMddHHmmssRRRR
AByyyy\RMMddHHRRmmRR
\Myy\HMMdd\RRHHmmss99RR
What is ff? Is it current-milliseconds/100 or current-seconds/100?
If It's current-milliseconds/100 use this regex
\d{2}(\d{2})(\w{3})(\d{2})(\d{2})(\d{2})(\d{13})(\d{11}.\d{2})(\d+)
Pattern should contains minimum 4 random digits (e.g. yyRMMRddRHHRmmRss)
You are asking for something that may not yield one unique match.
For example, the pattern 20110221318763521 could be matched in many ways:
20110221318323521
yyRMMRddRHHRmmRss => 20-10-21 18:23:21
yyMMRRddRHHRmmRss => 20-11-21 18:23:21
yyRRMMddRHHRmmRss => 20-02-21 18:23:21
yyRMMRddRHHmmRssR => 20-10-21 18:32:52
...
I have multiple formats of strings from which I have to extract exactly 10 digit number.
I have tried the following regexes for it. But it extracts the first 10 digits from the number instead of ignoring it.
([0-9]{10}|[0-9\s]{12})
([[:digit:]]{10})
These are the formats
Format 1
KINDLY AUTH FOR FUNDS
ACC 1469007967 (Number needs to be extracted)
AMT R5 000
DD 15/5
FROM:006251
Format 2
KINDLY AUTH FOR FUNDS
ACC 146900796723423 **(Want to ignore this number)**
AMT R5 000
AMT R30 000
DD 15/5
FROM:006251
Format 3
PLEASE AUTH FUNDS
ACC NAME-PREMIER FISHING
ACC NUMBER -1186 057 378 **(the number after - sign needs to be extracted)**
CHQ NOS-7132 ,7133,7134
AMOUNTS-27 000,6500,20 000
THANKS
FROM:190708
Format 4
PLEASE AUTHORISE FOR FUNDS ON AC
**1162792833** CHQ:104-R8856.00 AND (The number in ** needs to be extracted)
CHQ:105-R2772.00
REGARDS,
To match those numbers including the formats to have either 10 digits or 4 space space 3 space 3, you might use a backreference \1 to a capturing group which will match an optional space.
Surround the pattern by word boundaries \b to prevent the digits being part of a larger word.
\b\d{4}( ?)\d{3}\1\d{3}\b
Regex demo
Your expression seems to be fine, just missing a word boundary and we might want to likely modify the second compartment, just in case:
\b([0-9]{10}|[0-9]{4}\s[0-9]{3}\s[0-9]{3})\b
In this demo, the expression is explained, if you might be interested.
Adding a word boundary \b helps. The regex becomes: (\b([0-9]{10}|[0-9\s]{12})\b).
Check it here https://regex101.com/r/6Hm8PD/2
I have the following problem :
This is my RegEx-Pattern :
\d*[a-z A-Z][a-zA-Z0-9 _?!()\/\\]*
It allows anything but numbers that stand alone like : 1 , 11 , 111 or so on.
My question : How can I set the overall Length of the input regardless of the matches ?
i tried it with several options like {1,30} before each match and i put the regex in a group with ( ) and then {1,30} but it still doesnt work.
If anyone could help me i would appreciate it :).
Allowed string:
Group1
Group 1
1Group
Group!?()\/
Group !()\?!
a1 a1 a1 a1
Not Allowed:
1
11
And so on. {1,30} after a match restricts the number of how many times i can input the match. What i want to know is: How can i set the maximum length of my above RegEx, like after 30 chars the input is reached regardless of the matches?
In order to disallow a numeric string input only, you can use a negative look-ahead (?!\d+$) and to set a limit to the input, use a limiting quantifier {1,30}:
(?!\d+$)[a-zA-Z0-9 _?!()\/\\]{1,30}
See demo
Note that if you plan to match whole strings, you'd need anchors: ^ at the beginning will anchor the regex to the beginning of string, and $ will anchor at the end.
^(?!\d+$)[a-zA-Z0-9 _?!()\/\\]{1,30}$
See another demo
I have the following line :
3EAM7A 1 3 EI AMANDINE MRV SHP 70 W 0 SH3-A1 1 SHP 70W OVOIDE AI E27 SON PIA PLUS
I'd like to get the string : EI AMANDINE MRV SHP 70 W. So I decided to select the strings between 1 (can also be 2, 3 or 99) and 0 (can also be 1, 2, 3, 4 or 5).
I tried :
(0|1|2|3|99)(.*)(0|1|2|3|4|5)
But I have this result :
EAM7A 1 3 EI AMANDINE MRV SHP 70 W 0 SH3-A1 1 SHP 70W OVOIDE AI E
that is not what I want to obtain.
Do you have an idea in regex to make that selection work ?
Thanks !
You were pretty close! Try this:
\b(?:0|1|2|3|99) ([^0|1|2|3|99].*?) (?:0|1|2|3|4|5)\b
Regex101
I think that you want to match "word" 4 to 9?
Your desired match will be in group 1
^(\S+\s){3}((\S+\s){6})
Enable the multiline option if you have a whole file of subject strings.
You can try with:
\s(?:[0-3]|99)\s([A-Z].*?)\b(?:[0-5])\b
DEMO
and get string by group $1. Or if your language support look around, try:
(?<=\s[0-3]\s|99)[A-Z].+?(?=\s[0-5]\s)
DEMO
to get match directly.
Another solution that is based on matching all initial space + digit sequences:
\b(?:(?:[0-3]|99)\b\s*)+(.*?)\s*\b(?:[0-5])\b
See demo
The result is in Group 1.
With \b(?:(?:[0-3]|99)\b\s*)+ the rightmost number from the allowed leading set is picked.
You can use following regex :
(?:(?:[0-3]|99)\s)+(.*?)\s(?:[0-5])\s
See demo https://regex101.com/r/iX6oE1/6
Also note that for matching a range of number you can use a character class instead of multiple OR.
I have a variable like this
var = "!123abcabc123!"
i'm trying to capture all the '123' and 'abc' in this var.
this regex (abc|123) retrieve what i want but...
My question is: when i try this regex !(abc|123)*! it retrieve only the last iteration. what will i do to get this output
MATCH 1
1. [1-4] `123`
MATCH 2
1. [4-7] `abc`
MATCH 3
1. [7-10] `abc`
MATCH 4
1. [10-13] `123`
https://regex101.com/r/mD4vM8/3
Thank you!!
If your language supports \G then you may free to use this.
(?:!|\G(?!^))\K(abc|123)(?=(?:abc|123)*!)
DEMO