preg-match

PHP Regex for filename

不问归期 提交于 2019-12-12 18:25:46
问题 I made the user possible to change file names through a textarea, but now I'm having a regex problem. As I see for Windows 7, these characters only are not allowed for filenames: \ / : * ? < > | But I stubbornly, perhaps also wisely, choose to minimize the regex to ONLY these special characters: - _ . All the others should have to be cut. Can someone help me out with this regex? preg_replace all but: A-Za-z0-9 and - _ . I still really don't get the hang of it. 回答1: preg_replace('/[^A-Za-z0-9

Is my preg_match syntax valid?

[亡魂溺海] 提交于 2019-12-12 18:13:30
问题 I'm adding an if statement to my database abstraction layer to pick out any attempted queries to a handful of database tables. Basically, if my application attempts to create, read or destroy data from a database table called either members or members_profiles I want to invoke my if statement. if ( preg_match('/INSERT INTO [members|members_profiles]/', $sql) || preg_match('/UPDATE [members|members_profiles]/', $sql) || preg_match('/DELETE FROM [members|members_profiles]/', $sql)) { // do if

String matching

99封情书 提交于 2019-12-12 18:12:23
问题 I want to get column names from SQL 'CREATE' query. Query: CREATE TABLE 'test' ( 'col1' INT( 10 ) NOT NULL , 'col2' VARCHAR( 50 ) NOT NULL , 'col3' DATE NOT NULL ) ENGINE = MYISAM ; Code: preg_match_all("/'(.+)' (\w+)\(? ?(\d*) ?\)?/", $sql, $_matches, PREG_SET_ORDER); Output: Array ( [0] => Array ( [0] => 'col1\' INT( 10 ) [1] => col1\ [2] => INT [3] => 10 ) [1] => Array ( [0] => 'col2\' VARCHAR( 50 ) [1] => col2\ [2] => VARCHAR [3] => 50 ) [2] => Array ( [0] => 'col3\' DATE [1] => col3\ [2]

PHP Explode from first number (integer)

大城市里の小女人 提交于 2019-12-12 15:16:50
问题 I want to explode some test with first number (integer) in it . Here are some words . Avant Browser 2013 Build 110 Firefox 23.0 Beta 10 Google Chrome 29.0.1547.41 Beta i am trying this but its not working. $in ='Avant Browser 2013 Build 110'; preg_match("/\d[^A-Za-z]+([A-Za-z\s]+)/", $in, $match); echo $match[0]; Output needed is :- Avant Browser Firefox Google Chrome Please help 回答1: Try this regex: ^.*?(?=\d) //start lookup from linestart, get all symbols before first number occurance 回答2:

Regular expression help in PHP (8 hexadecimal characters followed by an underscore)

社会主义新天地 提交于 2019-12-12 13:09:12
问题 I want to validate if my input consists starting with 8 hexadecimal characters followed by a underscore, followed by any number of charters with any value. Im currently using the following regular expression: preg_match('/^[0-9A-Fa-f]{8}_*/', $value); But this expression does not fulfill my needs because it behaves the following way Result: 1A345678 (true) 1A345678_add (true) 1234567890 (true) ABSDBASDB (false) Expected result: 1A345678 (false) 1A345678_add (true) 1234567890 (false) ABSDBASDB

PHP trying to allocate 127 TB of memory and memory leak with preg_match and preg_replace

纵饮孤独 提交于 2019-12-12 12:24:56
问题 I think I have found a problem that seems to create a memory leak in Apache / PHP when unicode characters as a delimiter or sometimes anywhere in a regular expression with preg_match and preg_replace . It is possible that this happens in more preg_* methods. Test case 1 Create a new PHP file test.php with the following contents: <?php preg_match( '°test°i', 'test', $matches ); Test case 2 Create a new PHP file test.php with the following contents: <?php preg_match( '°', 'test', $matches );

Suppressing full pattern match in regex (preg_match())

回眸只為那壹抹淺笑 提交于 2019-12-12 11:25:21
问题 The returned matches array contains as the first element the entire string matched, followed by the captured groups. I can't locate an option on php.net to just return the captured groups? Is there one? 回答1: No, it is standard for 0 to contain the entire matched string. If it were of a concern, you could always unset($matches[0]) (which won't affect the keys) or array_slice($matches, 1) . 来源: https://stackoverflow.com/questions/7949436/suppressing-full-pattern-match-in-regex-preg-match

How to use preg_match to extract data?

女生的网名这么多〃 提交于 2019-12-12 07:22:26
问题 I am pretty new to the use of preg_match. Searched a lot for an answer before posting this question. Found a lot of posts to get data based on youtube ID etc. But nothing as per my needs. If its silly question, please forgive me. I need to get the ID from a string with preg_match. the string is in the format [#1234] Subject How can I extract only "1234" from the string? 回答1: One solution is: \[#(\d+)\] This matches the left square bracket and pound sign [# , then captures one or more digits,

allow parentheses and other symbols in regex

≡放荡痞女 提交于 2019-12-12 07:14:24
问题 I've made this regex: ^[a-zA-Z0-9_.-]*$ Supports: letters [uppercase and lowercase] numbers [from 0 to 9] underscores [_] dots [.] hyphens [-] Now, I want to add these: spaces [ ] comma [,] exclamation mark [!] parenthesis [()] plus [+] equal [=] apostrophe ['] double quotation mark ["] at [@] dollar [$] percent [%] asterisk [*] For example, this code accept only some of the symbols above: ^[a-zA-Z0-9 _.,-!()+=“”„@"$#%*]*$ Returns: Warning: preg_match(): Compilation failed: range out of order