regex

Regex for URL with query string

喜欢而已 提交于 2021-02-04 18:50:06
问题 I'm trying to create a regular expression to use as a rule in fiddler. I'm not very good at regular expressions. This regular expression: http://myServer:28020/MyService/ItemWebService.json?([a-zA-Z]+) Matches the URL below: http://myServer:28020/MyService/ItemWebService.json?action=keywordSearch&username=StockOnHandPortlet&sessionId=2H7Rr9kCWPgIZfrxQiDHKp0&keywords=blue&itemStatus=A So far so good. But why when I try this regular expression: http://myServer:28020/MyService/ItemWebService

Multiply regex matches and replace them in string

可紊 提交于 2021-02-04 18:41:30
问题 I'm trying to multiply the amounts in a recipe using regex replace. Here is the example HTML code <div id="ingredients"> <ul> <li>2 bananas, sliced</li> <li>1 cup frozen strawberries</li> <li>8 oz. low fat vanilla yogurt</li> </ul> </div> I got as far as here. I'm trying to find a way to multiply the matched number and then replace the old one with the multiplied one: var str = document.getElementById('ingredients').innerHTML; var regex = /[0-9]+(?:\.[0-9]*)?/g; str = str.replace(regex, "$&"

Perl regular expression matching on large Unicode code points

折月煮酒 提交于 2021-02-04 18:16:26
问题 I am trying to replace various characters with either a single quote or double quote. Here is my test file: # Replace all with double quotes " fullwidth “ left ” right „ low " normal # Replace all with single quotes ' normal ‘ left ’ right ‚ low ‛ reverse ` backtick I'm trying to do this... perl -Mutf8 -pi -e "s/[\x{2018}\x{201A}\x{201B}\x{FF07}\x{2019}\x{60}]/'/ug" test.txt perl -Mutf8 -pi -e 's/[\x{FF02}\x{201C}\x{201D}\x{201E}]/"/ug' text.txt But only the backtick character gets replaced

Replacing string in linux using sed/awk based

血红的双手。 提交于 2021-02-04 18:16:13
问题 i want to replace this #!/usr/bin/env bash with this #!/bin/bash i have tried two approaches Approach 1 original_str="#!/usr/bin/env bash" replace_str="#!/bin/bash" sed s~${original_str}~${replace_str}~ filename Approach 2 line=`grep -n "/usr/bin" filename` awk NR==${line} {sub("#!/usr/bin/env bash"," #!/bin/bash")} But both of them are not working. 回答1: You cannot use ! inside a double quotes in BASH otherwise history expansion will take place. You can just do: original_str='/usr/bin/env

Replacing string in linux using sed/awk based

余生颓废 提交于 2021-02-04 18:16:09
问题 i want to replace this #!/usr/bin/env bash with this #!/bin/bash i have tried two approaches Approach 1 original_str="#!/usr/bin/env bash" replace_str="#!/bin/bash" sed s~${original_str}~${replace_str}~ filename Approach 2 line=`grep -n "/usr/bin" filename` awk NR==${line} {sub("#!/usr/bin/env bash"," #!/bin/bash")} But both of them are not working. 回答1: You cannot use ! inside a double quotes in BASH otherwise history expansion will take place. You can just do: original_str='/usr/bin/env

Javascript regexObj.exec() says TypeError: pattern.exec is not a function

梦想与她 提交于 2021-02-04 18:15:57
问题 I want to extract image name from img tag with regex in javascript . My problem is that console.log() throws Exception: TypeError: pattern.exec is not a function . JS: $("label.btn-danger").on('click',function(e){ e.preventDefault(); var src = $(this).parents("label").find("img").attr("src"); var pattern = "/\/([A-Z0-9_-]{1,}\.(?:png|jpg|gif|jpeg))/ig"; var result = pattern.exec(src) console.log(result); }); 回答1: var pattern = "/\/([A-Z0-9_-]{1,}\.(?:png|jpg|gif|jpeg))/ig"; Creates a string.

regex: getting backreference to number, adding to it

只愿长相守 提交于 2021-02-04 18:13:27
问题 Simple regex question: I want to replace page numbers in a string with pagenumber + some number (say, 10). I figured I could capture a matched page number with a backreference, do an operation on it and use it as the replacement argument in re.sub . This works (just passing the value): def add_pages(x): return x re.sub("(?<=Page )(\d{2})",add_pages(r"\1") ,'here is Page 11 and here is Page 78\nthen there is Page 65',re.MULTILINE) Yielding, of course, 'here is Page 11 and here is Page 78\nthen

regexp Parsing ISO-8601

北战南征 提交于 2021-02-04 18:10:07
问题 As a followup to a question I am trying to help with: javascript date.parse difference in chrome and other browsers I need assistance in updating the regex I found here: JavaScript: Which browsers support parsing of ISO-8601 Date String with Date.parse to handle 2011-11-24T09:00:27+0200 It currently only is supposed to handle the 2011-11-24T09:00:27Z version of the ISO date i.e. the rx in function(s){ var day, tz, rx= /^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*)?)([zZ]|([+\-])(\d\d):(\d\d))?$/, p= rx

What is the purpose of the 'y' sticky pattern modifier in JavaScript RegExps?

久未见 提交于 2021-02-04 17:54:10
问题 MDN introduced the 'y' sticky flag for JavaScript RegExp. Here is a documentation excerpt: y sticky; matches only from the index indicated by the lastIndex property of this regular expression in the target string (and does not attempt to match from any later indexes). There's also an example: var text = 'First line\nSecond line'; var regex = /(\S+) line\n?/y; var match = regex.exec(text); console.log(match[1]); // prints 'First' console.log(regex.lastIndex); // prints '11' var match2 = regex

How to replace everything but a specified string using regex

ぃ、小莉子 提交于 2021-02-04 17:46:18
问题 I've been looking through and out of stackoverflow for this, but I haven't had any luck. The string I want to work with is "xbananay", where 'x' and 'y' can be any random combination of letters or numbers with any length. So my string could simply be "qrstbananag", but it could also be "abcbanana12345" for example. I want to use, and only use , javascript's replace function to replace everything BUT "banana". I already have some regex that can find banana, but the replace function, as