lundi 23 novembre 2015

SQLite regular Expressions regex get exact word by number

I have a string like the following in a sqlite 1 column:

1a 2B 3c 354 AfS 151 31s2fef 1fs31 3F1e2s 84f64e 45fs

space separated, x amount of characters 0-9, a-z, A-Z, there might be punctuation I'm not sure, but it is definitely space separated.

I'm trying to make a regular expression so I can query the database by number of words. basically if I wanted to get the 6th "word" in the example I'd be looking for:

151

so I tried to make a regular expression that says if the Nth word = 151, return me that row.

Here's what I've got so far.

SELECT * FROM table1 WHERE column1 REGEXP ^((?:\S+\s+){1}){6}

That unfortunately gives me the first through sixth words, but I really want to pinpoint the 6th word like the example above.

Also, I was thinking so save room in the database I could get rid of the white space, I'd just need to know how to count a specific number of characters in to the string which I couldn't figure out either.

Thanks for the help, never written a regular expression before.

Aucun commentaire:

Enregistrer un commentaire