sql: put "beginning of line" and "end of line" within a charset...
hi,
i have this code: Code:
$pattern = '/([A-Z])([0-9])/'; any idea? i could add a space at the benigging and in the end all of my records... it would work, but it would be quite an horrible solution... thanks! |
What're the contents of 'string' and your database records likely to be? Just trying to get my head around what you're trying to do...
Also, surely '$splitted[i]' should be '$splitted[$i]'? (and would be easier to understand if you didn't put it in the SQL string directly) I would also change your while loop construct to a foreach loop, but that's more personal preference - though again it would make it easier to read. |
Quote:
Code:
$string = "BUBU23GH" Code:
$splitted = split('[ -. /\_]+',$string); $splitted[1] is "23" $splitted[2] is "GH" Code:
if (preg_match("/^[A-Z]+$/", $splitted[0])) { Code:
$i = 0; let's say i have a table with one field only (searchfield): Code:
searchfield how to get both "_BUBU23GH_" and "BUBU23GH" with the results? i have 2 ways: 1) modify the table records adding a particular char (like _) in the first and last position, then trim them away when getting the results (VERY uncomfortable) 2) modify the regular expressions so that [^A-Z] and [^0-9] include the special chars ^ and $ (begginning and end of line)... is it possible? i hope it's a bit clearer, now... |
Quote:
It would help if you provide a sample input file and the desired output file. Daniel B. Martin |
ok, i try to...
sql to create a test table: Code:
CREATE TABLE IF NOT EXISTS `test` ( Code:
$string = "BUBU23GH"; _BUBU23GH_ desired output is: BUBU23GH _BUBU23GH_ |
Here's your query:
SELECT searchfield FROM test WHERE searchfield REGEXP '[^A-Z]BUBU[^A-Z]' AND searchfield REGEXP '[^0-9]23[^0-9]' AND searchfield REGEXP '[^A-Z]GH[^A-Z]' The reason you do not get BUBU23GH in the output is because of the first condition. There, you are saying to select all searchField where the string does not start and does not end with a letter, which obviously BUBU23GH does. |
Quote:
is there a way to fix it? i can't believe nobody ever had the need to specify a charset with beginning and end of lines... i mean something like [^A-Z$^]... |
solved with:
Code:
$unwanted = "[^0-9]"; |
All times are GMT -5. The time now is 07:29 PM. |