OsakaWebbie
Programmer
Is there any way to use a REGEXP but have it tell me where in the string it occurred? Or is there a way to do what I want without REGEXP?
I have a field (lyrics of songs) that, in the case of songs sung in Japanese, contains Japanese lyrics followed by the English equivalent. I want to be able to find the spot where the English starts and either return just the Japanese or return just the English. There may be sets of square brackets with English characters (guitar chords) inline in either the Japanese or English, so I also have to watch out for that. To help you understand what I mean, let's hypothetically say that there is a regexp "function" that returns the index to the first occurrence of a match (which MySQL's REGEXP operator does not appear to do). If that were the case, I would do something like this:
I have to use the carat (force the match to be only at the beginning of a line) because there may be chords inline in the Japanese, which of course contain English letters.
The messy-looking stuff in parentheses followed by the question mark is just to check for a possible chord at the very beginning of the English lyrics. If there is a way without regexp to do just the check for the alphabet at the beginning of lines (the equivalent of just '^[a-zA-Z]'), I can make a rule for my DB that the very first character of the English will never a chord, to simplify the challenge. But I have used regexp so long that it is hard to imagine how to do even the simplified search without it. Any thoughts?
I have a field (lyrics of songs) that, in the case of songs sung in Japanese, contains Japanese lyrics followed by the English equivalent. I want to be able to find the spot where the English starts and either return just the Japanese or return just the English. There may be sets of square brackets with English characters (guitar chords) inline in either the Japanese or English, so I also have to watch out for that. To help you understand what I mean, let's hypothetically say that there is a regexp "function" that returns the index to the first occurrence of a match (which MySQL's REGEXP operator does not appear to do). If that were the case, I would do something like this:
Code:
SELECT SUBSTRING(Lyrics,0,REGEXP(Lyrics,'^(\[[^\]]\])?[a-zA-Z]')) AS Japanese FROM song...
SELECT SUBSTRING(Lyrics,REGEXP(Lyrics,'^(\[[^\]]\])?[a-zA-Z]')) AS English FROM song...
The messy-looking stuff in parentheses followed by the question mark is just to check for a possible chord at the very beginning of the English lyrics. If there is a way without regexp to do just the check for the alphabet at the beginning of lines (the equivalent of just '^[a-zA-Z]'), I can make a rule for my DB that the very first character of the English will never a chord, to simplify the challenge. But I have used regexp so long that it is hard to imagine how to do even the simplified search without it. Any thoughts?