regex

Javascript regex to match only up to 11 digits, one comma, and 2 digits after it

て烟熏妆下的殇ゞ 提交于 2021-01-29 12:10:18
问题 I have a textbox where I want only allowed up to 11 digits, an optional comma, and two more digits after it. Anything else should not be rendered when the key is pressed into the textbox: $('#txt').keypress(function (e) { var code = e.which; var key = String.fromCharCode(code); // REGEX TO AVOID CHARS & A DOT (.) var pattern = /[a-zA-Z]|\./g; var isMatch = pattern.test(key); if (isMatch) { // DO NOT RENDER CHARS & dot e.preventDefault(); } }); The above code works when an invalid key is

extracting substring using regex in sas

蓝咒 提交于 2021-01-29 12:09:30
问题 I have a string like this: dfjkldjfdsldfkdslfkd dfkdjd/FR018/HAHDFKDLFDAFHDKFJL/ABCD//NAME/I WANT TO EXTRACT THIS/JJJJ//NAME/blah blah blah in this string, I want to be able to pull the string I WANT TO EXTRACT THIS . In other words, I want to extract everything that follows /ABCD//NAME/ and before /JJJJ . how can I write this using regular expressions? thanks 回答1: I am not familiar with SAS, but from the documentation it seems like you can do: re = prxparse('/\/ABCD\/\/NAME\/(.*?)\/(.*?)\

Replace each item differently, regex c++

坚强是说给别人听的谎言 提交于 2021-01-29 11:50:40
问题 I have a long string and I need to convert digits to words (ex. 5 to five). Can I do this with a regex? I tried using regex_replace , but this changed all the numbers to the one that was found first (ex. it converted "5 10 1 0" to "five five five five", but I need "five ten one zero"). This was my attempt: string text ="a lot of text"; regex pattern("(\\d)+"); smatch result; int x; string buffer; while (regex_search(text, result, pattern)) { buffer = result[0]; x = atoi(buffer.c_str());

regex start and end matching

守給你的承諾、 提交于 2021-01-29 11:35:43
问题 So I'm having a little regex trouble, I have an expression that matches the starting with and the ending with separately. The problem occurs when I try to match the starting with and ending with both in the same expression and I don't understand why that would be a problem. I've even tried accounting for the content between the start and end tags, still no luck. Works: /^([ ])?\[(\/?)gaiarch(=[^"]*)?]([ ])?/ig Works: /([ ])?\[(\/?)gaiarch(=[^"]*)?]([ ])?$/ig Doesn't work: /^([ ])?\[(\/?

Replace multiple lines with regex

Deadly 提交于 2021-01-29 11:23:06
问题 Given the following text, I want to remove everything in data_augmentation_options{..} i.e., input is : batch_size: 4 num_steps: 30 data_augmentation_options { random_horizontal_flip { keypoint_flip_permutation: 0 keypoint_flip_permutation: 2 keypoint_flip_permutation: 1 keypoint_flip_permutation: 4 keypoint_flip_permutation: 3 keypoint_flip_permutation: 6 keypoint_flip_permutation: 5 keypoint_flip_permutation: 8 keypoint_flip_permutation: 7 keypoint_flip_permutation: 10 keypoint_flip

Why is /[\w-+]/ a valid regex but /[\w-+]/u invalid?

北战南征 提交于 2021-01-29 11:20:57
问题 If I type /[\w-+]/ in the Chrome console, it accepts it. I get a regex object I can use to test strings as usual. But if I type /[\w-+]/u , it says VM112:1 Uncaught SyntaxError: Invalid regular expression: /[\w-+]/: Invalid character class . In Firefox, /[\w-+]/ works fine, but if I type /[\w-+]/u in the console, it just goes to the next line as if I typed an incomplete statement. If I try to force it to create the regex by running eval('/[\w-+]/u') , it tells me SyntaxError: invalid range in

Split PHP Variable in to array

帅比萌擦擦* 提交于 2021-01-29 11:20:41
问题 A php variable contains $string = "256 Engineering Maths-I 21 -1 21 F"; printing $string gives output 256 Engineering Maths-I 21 -1 21 F this variable should split in to $n[0] = "256"; $n[1] = "Engineering Maths-I"; $n[2] = "21"; $n[3] = "-1"; $n[4] = "21"; $n[5] = "F"; I have tried with $n = explode(" ", $string); but it is splitting in to 2 parts Please help me 回答1: What you are probably looking at is a tab separated string Do this $n = explode("\t", $string); UPDATE The answer was that the

Best way to convert a regex match into an integer in C?

谁说胖子不能爱 提交于 2021-01-29 11:17:39
问题 I am using the standard <regex.h> library to match a complex string. Some matches are integers and my current solution is to use to_integer : int to_integer(regmatch_t match, const char* str) { char buffer[16]; int end = match.rm_eo - match.rm_so; memcpy(buffer, &str[match.rm_so], end); buffer[end] = '\0'; return atoi(buffer); } struct data { int foo, bar, baz; }; struct data fetch(char *string) { int groups = 4; regmatch_t matches[groups]; if (regexec(&regex, string, groups, matches, 0))

How do I regex remove whitespace and newlines from a text, except for when they are in a json's string?

三世轮回 提交于 2021-01-29 11:11:10
问题 I have an instruction like: db.insert( { _id:3, cost:{_0:11}, description:"This is a description.\nCool, isn\'t it?" }); The Eclipse plugin I am using, called MonjaDB splits the instruction by newline and I get each line as a separate instruction, which is bad. I fixed it using ;(\r|\n)+ which now includes the entire instruction, however, when sanitizing the newlines between the parts of the JSON, it also sanitizes the \n and \r within string in the json itself. How do I avoid removing \t, \r

php regex: modify to only allow one word

那年仲夏 提交于 2021-01-29 10:54:48
问题 I'm using the contact form 7 plugin for wordpress in combination with contact form db to display the field results in the front end. I'm trying to filter out the results in the shortcode, e.g. <?php echo do_shortcode('[cfdb-value form="Testing" filter="FirstField~~/^s/"]'); ?> This filter will only show values of FirstField that start with the letter s , is it possible to adapt this code to only show one word values (i.e. words with no spaces in). If this is at all possible? Any suggestions