posix-ere

Match digits in [g]awk

坚强是说给别人听的谎言 提交于 2019-12-20 03:46:08
问题 I'm stumped! Trying to write an awk regex to match a string against 11 digits. I've tried: if (var ~ /^[0-9]{11}$/ ) if (var ~ /^([0-9]){11}$/ ) if (var ~ /^([0-9]{11})$/ ) if (var ~ /^[0-9]{11}/ ) # altho I really do need to check the whole str if (var ~ /[0-9]{11}/ ) If I use this.... if (var ~ /^[0-9]+/ ) Then I get a match - but I need to check for exactly 11 digits. 回答1: You described your problem, but didn't tell us your awk version. It is an important information. but this may work for

ereg_replace for PHP 5.3 +?

怎甘沉沦 提交于 2019-12-19 10:45:30
问题 I've seen a solution for not having to rework usage of the ereg function for PHP 5.3: Good alternative to eregi() in PHP It uses if(!function_exists.... Is there a function that can be used in this way for ereg_replace ? ereg_replace("<!--.*-->","",$str); ereg_replace("[^a-z,A-Z]", "", $str); 回答1: Use the PCRE function preg_replace instead: preg_replace("/<!--.*-->/", "", $str); preg_replace("/[^a-z,A-Z]/", "", $str); POSIX ERE is (nearly) a complete subset of PCRE. So you can use (nearly)

What is the difference between split() and explode()?

孤者浪人 提交于 2019-12-18 11:41:49
问题 The PHP manual for split() says This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged...Use explode() instead. But I can't find a difference between split() and explode() . join() hasn't been deprecated, so what gives? 回答1: It's been deprecated because explode() is substantially faster because it doesn't split based on a regular expression, so the string doesn't have to be analyzed by the regex parser preg_split() is faster and uses PCRE regular

ereg_replace to preg_replace?

自古美人都是妖i 提交于 2019-12-18 04:08:41
问题 How can I convert ereg_replace(".*\.(.*)$","\\1",$imgfile); to preg_replace... ? ? I'm having trouble with it? 回答1: preg_replace("/.*\.(.*)$/", "\\1", "foo.jpg") I don't know why PHP requires the / delimiters. The only reason Perl, JS, etc. have them is that they allow regex literals, which PHP doesn't. 回答2: You should know 4 main things to port ereg patterns to preg: Add delimiters (/): 'pattern' => '/pattern/' Escape delimiter if it is a part of the pattern: 'patt/ern' => '/patt\/ern/'

ereg/eregi replacement for PHP 5.3 [duplicate]

蓝咒 提交于 2019-12-17 15:58:12
问题 This question already has answers here : How can I convert ereg expressions to preg in PHP? (4 answers) Closed 7 months ago . I'm sorry to ask a question but I am useless when it comes to understanding regex code. In a php module that I didn't write is the following function function isURL($url = NULL) { if($url==NULL) return false; $protocol = '(http://|https://)'; $allowed = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; $regex = "^". $protocol . // must include the protocol '(' . $allowed . '{1,63}\.

How to change PHP's eregi to preg_match [duplicate]

风流意气都作罢 提交于 2019-12-17 06:46:36
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How can I convert ereg expressions to preg in PHP? I need help, below is a small VERY basic regex to somewhat validate an email, I do realize it does not work the greatest but for my needs it is ok for now. It currently uses PHP's eregi function which php.net says is now a depreciated function and I should use preg_match instead, simply replacing erei with preg_match does not work, can someone show me how to

How to match version of a command using bash “=~”?

落花浮王杯 提交于 2019-12-13 03:28:06
问题 luajit -v LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/ I want to negate match the version part, and got LUAJIT_VERSION="2.1.0-beta3" at the beginning of bash script. I use: if ! [[ "$(luajit -v)" =~ LuaJIT\s+"$LUAJIT_VERSION".* ]]; then #rest of code But it seems not working whether I put $LUAJIT_VERSION between "" or not : Any part of the pattern may be quoted to force the quoted portion to be matched as a string ... If the pattern is stored in a shell variable

Converting an eregi_replace to a preg_replace

扶醉桌前 提交于 2019-12-12 05:29:20
问题 I am trying to parse some HTML snippets and want to clean them up for various reasons (XSS et al). I am currently trying to remove all of the attributes on any tag, except for the href on a anchor. I am doing this using a sequence of eregi_replace calls, but I am sure there is a smarter way of doing this using preg_replace and just a couple of lines of code, but I have not been able to get it to work. Can anyone help? Current code: $data_item = eregi_replace("<p[^>]*>","<p>", $data_item);

Scheduling Policy

自闭症网瘾萝莉.ら 提交于 2019-12-12 02:47:41
问题 While working on an embedded project; during changing of the scheduling policy from SCHED_OTHER to SCHED_RR I am getting timer issues and stream loading delays. Some issues are not coming during SCHED_OTHER but arriving at SCHED_RR (round robin). What effect will occur while changing the scheduling policies . What do I need to take care of when implementing kernel module in embedded projects during policy changes? 回答1: SCHED_RR is with a time slice so if the process completes the time slice

POSIX Regular Expressions: Excluding a word in an expression?

谁说我不能喝 提交于 2019-12-07 06:52:07
问题 I am trying to create a regular expression using POSIX (Extended) Regular Expressions that I can use in my C program code. Specifically, I have come up with the following, however, I want to exclude the word "http" within the matched expressions. Upon some searching, it doesn't look like POSIX makes it obvious for catching specific strings. I am using something called a "negative look-a-head" in the below example (i.e. the (?!http:) ). However, I fear that this may only be something available