Page 1 of 1
Regular Expressions
Posted: Tue Oct 15, 2013 10:53 pm
by lombert
Hi
I'm looking for a way to sort out one specific file-name. And I think Reg Exp is the way, but I'm a novice to this..
I want every file that starts with 6 numbers go in one direction and all other in one.
I have this start:
^[0-9]{6}
And that picks up this:
1: 123456
2: 123e345r
3: 111111-1
4: 121212
5: 232323_23234_abc
6: 000000_abc
7: 12345_232332_2
But I need it to look at the rest of the file also, I want number 3,5 and 6 also should be sorted out.
How would a Reg Exp look like how can do this?
Regular Expressions
Posted: Wed Oct 16, 2013 3:18 pm
by dkelly
Hello, so "^[0-9]{6}" matches #1,3,4,5,6 but you want it to match only #1,4? If so, add a EOL symbol to end: "^d{6}$"
Regular Expressions
Posted: Wed Oct 16, 2013 3:50 pm
by lombert
dkelly wrote: Hello, so "^[0-9]{6}" matches #1,3,4,5,6 but you want it to match only #1,4? If so, add a EOL symbol to end: "^d{6}$"
Hi
I did't make a good example. The test numbers was just for me to understand how it works.
The real file-name is like this;
First version look like this:
123456∞ (after the first 6 digits it can be anything)
And the other is like this:
12345∞ (after the first 5 digits it can be anything (but not another digit))
So I want the first example go in one direction and the second (or all other) in one other..
Regular Expressions
Posted: Wed Oct 16, 2013 7:16 pm
by freddyp
^d{6}.*
is the answer for routing all jobs that start with 6 digits. The .* is important because otherwise the regular expression only matches jobs with 6 digits and nothing else.
The other jobs follow "All other jobs". Then you can filter out the ones with 5 digits if still necessary. You cannot do the two at the same time as a name starting with 6 digits also starts with 5 digits.
Check out the movie on regular expressions in Switch on Youtube.
Freddy
Regular Expressions
Posted: Wed Oct 16, 2013 8:20 pm
by lombert
Thank you both!
What I can see (have not tested in the flow yet) it works. Tested all of them at Regex Tester.
Both "^d{6}.*" and "^(d{6})(.*)$" do the trick. Even my version works if I add ".*" ("^[0-9]{6}.*").
I will test more and will probably came back with more question.
Re: Regular Expressions
Posted: Wed Oct 14, 2015 1:03 pm
by lombert
I have an other question about how regular expression works.
Probably were easy answer..
I have a string like this "201510
151347" (yes its a date..)
I want to pick out the 7th and 8th digit (its underline above)
How should that reg ex look like?
Re: Regular Expressions
Posted: Wed Oct 14, 2015 2:56 pm
by gabrielp
Here's one solution from the other thread:
https://github.com/dominickp/SwitchPars ... Weekday.js
Code: Select all
// Pattern for parsing the string
var regex = /(\d{4})+(\d{2})+(\d{2})+(\d{2})+(\d{2})/;
regex.search(dateString);
var parsedYear = regex.cap(1);
var parsedMonth = regex.cap(2);
var parsedDay = regex.cap(3);
var parsedHour = regex.cap(4);
var parsedMinute = regex.cap(5);
// Log
if(debug == true) s.log(debugLevel, 'Parsed date values: ' + parsedYear + ', ' + parsedMonth + ', ' + parsedDay + ', ' + parsedHour + ', ' + parsedMinute);
Using this example, regex.cap(3) would return 15.