Start New Discussion within our Software Development Community

Greetings

So i'm trying to figure out how regex works and already run into a roadblock.
I figured out the easier ones, if a string only consists of numbers or letters.
But these required a little more thought it seems.

These are three random linen that i need to check up.

I B Tauris & Co Ltd

The Decline and Fall of the Roman Empire: v. 1-3

and a date that should be formated such as year/month/day
080803

How would i be able to write these.
I somehow think i need "may include" but not sure how to translate that to matches/regex.

The first and second line may contain letters, spaces, special characters and/or numbers.

And as i stated, the date should be formated as year/month/day.

Is this possible to do? or am i trying to hard with matches and regex and should maybe take some easier road that i havnt seen?

Well hopefully someone can help out, this community has been a great help for me so far

//Martin

You need to read short-handed for regular expression. It is standard, so you use your search on the Internet should give you some ideas.

For matching the first and second, you are talking about 'every single' character there. If you want, you need a '.' which means anything. And then use + which means at least 1. i.e. /.+/ which means to match anything with at least 1 character.

For your third, it must contains only number and there must be 6 digit only? If so, short-handed for digit is \d and you can limit the number to be found at 6. Also, you may want to check that the string contains only these 6 digits. i.e. /^\d{6}$/ which means to match from start and end with a digit number, and the there must be continuous 6 digit numbers in the string.

This article has been dead for over six months. Start a new discussion instead.