Skip to main content
Modified title to make the question seem less of a duplicate
Link
Steve Chambers
  • 39.8k
  • 29
  • 179
  • 222

How to count words in MySQL Regex Replace/ regular expression replacer?

Does anybody know howHow can I could have, in a MySQL query, have the same behaviour as the Regex.Replace function (for instance in .NET/C#)?

I need that because, as many people, I would like to count the number of words in a field. However, I'm not satisfied with the following answer (given several times on that site):

SELECT LENGTH(name) - LENGTH(REPLACE(name, ' ', '') +1 FROM table 

Because it doesn't give good results when there are more that one space between two words.

By the way, I think the Regex.Replace function may be interesting so all the good ideas are welcome !

Does anybody know how I could have, in a MySQL query, the same behaviour as the Regex.Replace function (for instance in .NET/C#)?

I need that because, as many people, I would like to count the number of words in a field. However, I'm not satisfied with the following answer (given several times on that site):

SELECT LENGTH(name) - LENGTH(REPLACE(name, ' ', '') +1 FROM table 

Because it doesn't give good results when there are more that one space between two words.

By the way, I think the Regex.Replace function may be interesting so all the good ideas are welcome !

How can I, in a MySQL query, have the same behaviour as the Regex.Replace function (for instance in .NET/C#)?

I need that because, as many people, I would like to count the number of words in a field. However, I'm not satisfied with the following answer (given several times on that site):

SELECT LENGTH(name) - LENGTH(REPLACE(name, ' ', '') +1 FROM table 

Because it doesn't give good results when there are more that one space between two words.

By the way, I think the Regex.Replace function may be interesting so all the good ideas are welcome !

Jeopardy compliance. Minor edit: grammar/spelling/case/punctation/etc. Removed greetings.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

Mysql MySQL Regex Replace

Does anybody know how I could have, in a MySQL query, the same behaviour as the Regex.Replace function (for instance in .NET/C#).?

I need that because, as many people, I would like to count the number of words in a field. However, I'm not satisfied with the following answer (given several times on that site):

SELECT LENGTH(name) - LENGTH(REPLACE(name, ' ', '') +1 FROM table 

becauseBecause it doesn't give good results when there are more that one space between two words.

By the way, I think the Regex.Replace function may be interesting so all the good ideas are welcome !

Mysql Regex Replace

Does anybody know how I could have, in a MySQL query, the same behaviour as the Regex.Replace function (for instance in .NET/C#).

I need that because, as many people, I would like to count the number of words in a field. However, I'm not satisfied with the following answer (given several times on that site)

SELECT LENGTH(name) - LENGTH(REPLACE(name, ' ', '') +1 FROM table 

because it doesn't give good results when there are more that one space between two words

By the way, I think the Regex.Replace function may be interesting so all the good ideas are welcome !

MySQL Regex Replace

Does anybody know how I could have, in a MySQL query, the same behaviour as the Regex.Replace function (for instance in .NET/C#)?

I need that because, as many people, I would like to count the number of words in a field. However, I'm not satisfied with the following answer (given several times on that site):

SELECT LENGTH(name) - LENGTH(REPLACE(name, ' ', '') +1 FROM table 

Because it doesn't give good results when there are more that one space between two words.

By the way, I think the Regex.Replace function may be interesting so all the good ideas are welcome !

Source Link
pierroz
  • 7.9k
  • 9
  • 52
  • 60
Loading