0

I have never come across RegEx in mySQL, In a column I have over 500 different server versions. is it possible to only fetch anything before a forward slash so that i can detect the most common servers by filtering out the versions?

Microsoft-IIS/7.5
Microsoft-IIS/6.0
Apache/2.2.24 (Unix)
Apache/2.2.15 (CentO
Apache/1.3.42 (Unix)
Apache/2.2.22 (Ubunt
Resin/3.0.23
Apache/2.2.0 (Linux/
3
  • Do you need a regex for this? It seems like 'index of' and 'substring' operations for / and ( are sufficient. Commented May 10, 2013 at 0:32
  • Do you have a regex that will match this already? Commented May 10, 2013 at 0:32
  • Also: regular-expressions.info/mysql.html Commented May 10, 2013 at 0:32

2 Answers 2

2

here,

SELECT DISTINCT SUBSTRING(version,1,LOCATE('/', version)-1) FROM TableName

because of DISTINCT, only unique rows are displayed.

Sign up to request clarification or add additional context in comments.

7 Comments

Wow i just searched and noticed that some of my gathered website server has "'; DROP TABLE server" could this be done purposely by webmasters?
someone has tried to mess with your database, how did you code in your php file?
Actually my database is run on my localhost, no outside access
i got it SELECT SUBSTRING(version,1,LOCATE('/', version)-1) as server, count(*) FROM TableName
I never new sql had those capabilities, well it has all come to fruition now, I wantto show you my results, oi41.tinypic.com/2qcic82.jpg what do you think, is for my disertation
|
2

In mysql regex cannot return a matched substring, but only return a boolean if the string matches a regular expression or not.

What you need is just a SUBSTR

SUBSTRING(col, 1, LOCATE('/', col) - 1)

but keep in mind that if there is no / in the string you'll end up with an empty string as a result

2 Comments

Yes, but that boolean can be used in a WHERE statement
@Christian Stewart: can be, so? "is it possible to only fetch anything before a forward slash"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.