Go through set of numbers and getting all possible matches - regex

I'm trying to go through a set of numbers like "123456789123456" and I want to be able to find every single combination of numbers I can, that is 8 long, and it's starting point increasing by 1 for every match.
I'll use [] as where the expression starts, and then counts from.
Example:
First match: [1]23456789123456 would find: 12345678
Second match: 1[2]3456789123456 would find: 23456789
Third match: 12[3]456789123456 would find: 34567891
and so on...
I'm fairly new to Regex so I don't have a ton of experience in it.

You don't really need regex for this. Just a simple loop should do:
Dim input As String = "123456789123456"
For i As Integer = 0 To input.Length - 8
Console.WriteLine(input.Substring(i, 8))
Next
12345678
23456789
34567891
45678912
56789123
67891234
78912345
89123456

Related

Regex for Match DataType and Precision

Suppose that we have the following Strings:
NUMBER
NUMBER(10)
I need a regex expression that matches theses strings to:
NUMBER => Group(0) = NUMBER
NUMBER(10) => Group(0) = NUMBER, Group(1) = 10
The following expression do this, but it seems a little bit ugly to me:
([^[\]]+)\(([^)]+)\)|([^[\]]+)
That is translated to 21 steps.
Since I'm not a regex expert, could anybody help me to improve this expression to make it faster?
This seems simpler:
([^(]+)(?:\((.+?)\))?
Regex101 says 6 steps for "NUMBER", and 13 for "NUMBER(10)".
You could consider adding ^ to the start and $ to the end to be stricter, in which case the step count goes up by 2 for each input example.

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

*NIX REGEXP number series

Am playing around with regexp's but this is my headache. I have a dynamic number which needs a suffix. The suffix is always 0 to 9, 99 or 999.
Example:
I have the number 461200 and now I want to create an regexp that will match 461200 to 461209. What I've learned it should be ^46120[0-9]$? Is this correct or somewhere to the left of hell?
Ok, let us assume it is correct and I now want to match 461200 - 461299? This is where I get lost.
^4612[0-9]{2}?
It cannot be. I am yet to figure this out.
Any help appreciated.
For 1 digit at the end you need:
^4612[0-9]$
2 digits at the end:
^4612[0-9]{2}$
3 digits at the end:
^4612[0-9]{3}$
The number in braces {} means the number of time the preceding character or set has to be repeated.
Ok, let us assume it is correct and I now want to match 461200 -
461299?
You can either repeat the desired character class by saying [0-9][0-9] or use quantifiers [0-9]{2}.
It can be either:
^4612[0-9][0-9]$
or
^4612[0-9]{2}$
Both would work.
maybe try this regex:
^4612\d{2}$

I need a single regex to check number comma and number

I need a regX which can match like 123,123 only. My regX is
var regX = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])*$/;
but its currently matching 123,123 and 123, as well
Valid case: 123,123 or 123,000 or 000,000
Invalid case: 123.123 or 123?123 or '123'.'123'
you should use this regex = \d+(,\d+)+
You might want to use the {x,y} quantifier. I matches at least X of the item, and at most Y. If you leave one out, it has no limit in that direction. If you just have one number, with no comma it matches exactly that amount.
Exactly three digits:
(\d{3}),(\d{3})
Three or more
(\d{3,}),(\d{3,})
Between 2 and 7 digits:
(\d{2,7}),(\d{2,7})
And so on...
It looks like you're actually trying to match a number with thousand separators.
Try this: /\d{1,3}(?:,\d{3})*/
If your numbers are positive integers you can use: \d+,\d+
If you want floating point numbers as well: (\d|.)+,(\d|.)+
although this will also match malformed numbers with multiple or misplaced decimal points including .,. etc.

How to match a one of a set of numbers?

I am trying to match a group of numbers in regex that consist of one of the following:
1,2,3,4,5,6,7,8,9,10,11
But I am having trouble figuring out the regex.
For single digits this pattern worked fine "0|1|2|3|4|5|6|7|8|9" but it fails on double digit numbers. For example 12 passes as ok due to the regex finding the 1 in 12.
You can use begin and end anchors to force the whole string to be matched:
^(0|1|2|3|4|5|6|7|8|9|10|11)$
Which can be shortened to:
^(\d|10|11)$
This will work if you want to check if just one number is between 0 and 11.
^[0-9]$|^1?[0-1]$
If you want to match a string like:
1,2,3,12,32,5,1,6,8, 11
and match 0-11 then you can use the following:
(?<=,|^)([0-9]|1?[0-1])(?=,|$)
use this regex ^(0|1|2|3|4|5|6|7|8|9|(10)|(11))$