Finding first five digits in a var with Regex [closed] - regex

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a variable that looks like this: AF1400006
I want to use regular expressions in order to return the number "14000".
I have gone through many threads here, but none quite seems to get me anywhere.
Thanks!
EDIT:
I don't see what's up with the downvotes, isn't this a forum for asking questions?
Anyhow, I solved my problem now, thanks for the help :-) For those wondering, I used it in a scanning software called Drivve Image to use parts of a barcode on a document as the name of the output folder. The software uses a unique regex formatting which seemed to be my issue.

You would need to use something like \d{5} which will match 5 digits.
Depending on the language you are using you would then access whatever the group matched.
For instance, in Java:
String str ="AF1400006";
Pattern p = Pattern.compile("\\d{5}");
Matcher m = p.matcher(str);
if(m.find())
System.out.println(m.group());
Which yields the number you are after.
An example of the expression is available here.

Related

One Regex, 2 results [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 days ago.
Improve this question
I am using XMPie and need a regex to character count for me. My Regex is ^[\S\s]{1,800}$ but I am getting a different result with the refresh preview button than the next screen button. I had a support case on it and it went all the way to R&D and they basically said, there is nothing we can do, try a different expression. I think one button must be implemented with C# and the other with JS or some such thing. What seems to be happening is that one is counting a return once (refresh), while the other is counting 2 characters for it. I think it must see it as \r or \n and count that as 2. Any ideas on how I could modify my expression to prevent that? I mostly just want consistency, so making it explicitly count it twice, or not count it at all would be more livable than differing results, especially as refresh is lower.
Thanks so much for any help!
I have tried a slew of different expressions, but I am not great with regex and nothing has given me a better result.

TCL - Fetch string between strings [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a large chunk of data and would like to extract a value of a particular field using TCL regexp.
ip="1.2.3.4" protocol="SFTP" username="abcd"
Need to extract the word SFTP without double quotes, the former and later fields can be ip,username or something else. So regexp has to use the word protocol as reference.
In this case, I'd use:
regexp {\yprotocol="(.*?)"} $theString -> theProtocol
However, if this is parsing XML then I'd actually use an XML handling extension like tDOM.

Regex - finding strings between signs [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I was trying to solve this by myself but there are only solutions for cases like that:
"text" "text2" "text3"
I need to write a pattern which takes strings starting with '-' sign, expected result is shown below:
Input:
-something/3443/kk-somethingelse/111/333/zz
-text/ff/33/33/zz
Output:
1. something/3443/kk
2. somethingelse/111/333/zz
3. text/ff/33/33/zz
as individual grups.
Thanks in advance and sorry I couldnt manage that.
Try this pattern, with global flag:
-([^-\s]+)
Demo link
I would exclude line breaks as well:
-([^-\r\n]+)

I need regular expression that will receive exactly 9 digits starting with 5 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have tried many alternatives but I am not reaching anywhere
/^[5]\d{9}$
can someone help.
Your regex must be like below,
^5\d{8}$
You mean this?
/5[0-9]{8}/
First a five, and then 8 times a digit.
If you want it to match anywhere, use this
/5\d{8}/
If you want it to be on a line by itself, use this instead
/^5\d{8}$/
The caret (^) means it must occur at the start of a line, and the dollar ($) means it must occur at the end of a line.

Regex to get string till it hits a comma [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Let's say I have a string like this: "1367,14,243,540"(will always have 4 number and only numbers, no decimal places and always separated by comma)
How should the regex look like that would allow me to pick/filter out/return lets say 243 from the string?
here is your regex if you insist on a regex /\d+/g (g here is for multiple selections in js, use matches with Microsoft framework) though you can use split (example using js):
var v='123,333,445,67';
console.log('split:');
console.log(v.split(',').map(function(n){return parseInt(n);}));
console.log('\nregex:');
console.log(v.match(/\d+/g).map(function(n){return parseInt(n);}));
jsfiddle
the numbers will be returned in an array, you can use the index to access the desired one, let's say 2.
note: split is faster than regex, you can test the difference in performance using jsperf.com
Edit: For those who are interested in the performance difference, check this link.
note2: map here is just for parsing the strings into integers, you can remove it if you want to keep them as strings.
try
^([[:digit:]]+,){2}([[:digit:]]+)
your desired number is in capture group #2.
As one of the comments says, you shouldn't really use a regex in this case. Always try to use the appropriate tool for the job, and in this case the regex is HUGE overkill.
Your problem is solved easily as this
$sourceString = "1367,14,243,540";
$numbers = explode(",", $sourceString);
$neededNumber = $numbers[2];
You just need to describe your string:
^(\d+,){2}(\d+)
"From the start, number followed by comma appears two times, then another number."
You can pick the number of the second group, i.e. \2 or $2.