Regular Expressions

Post Reply
lombert
Member
Posts: 166
Joined: Fri Feb 04, 2011 2:31 pm
Location: Sweden

Regular Expressions

Post 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?
Between jobs!
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Regular Expressions

Post 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}$"
lombert
Member
Posts: 166
Joined: Fri Feb 04, 2011 2:31 pm
Location: Sweden

Regular Expressions

Post 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..
Between jobs!
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Regular Expressions

Post 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
lombert
Member
Posts: 166
Joined: Fri Feb 04, 2011 2:31 pm
Location: Sweden

Regular Expressions

Post 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.
Between jobs!
lombert
Member
Posts: 166
Joined: Fri Feb 04, 2011 2:31 pm
Location: Sweden

Re: Regular Expressions

Post by lombert »

I have an other question about how regular expression works.

Probably were easy answer..

I have a string like this "201510151347" (yes its a date..) :)

I want to pick out the 7th and 8th digit (its underline above)

How should that reg ex look like?
Between jobs!
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Regular Expressions

Post 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.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Post Reply