regex

Regex to remove comments from SQL Query String using JavaScript

为君一笑 提交于 2021-01-29 17:57:00
问题 I managed to find the regex for handling /* */ cases but it doesn't work well for -- cases. How can I change my regex to fix this? var s = `SELECT * FROM TABLE_A /* first line of comment second line of comment */ -- remove this comment too SELECT * FROM TABLE_B`; var stringWithoutComments = s.replace(/(\/\*[^*]*\*\/)|(\/\/[^*]*)|(--[^*]*)/g, ''); /* Expected: SELECT * FROM TABLE_A SELECT * FROM TABLE_B */ console.log(stringWithoutComments); Thank you https://jsfiddle.net/8fuz7sxd/1/ 回答1: var

Regex for number range, and -1

倖福魔咒の 提交于 2021-01-29 17:53:59
问题 I need a regex (Javascript) that allows any positive number between 1 - 2048 (cannot be 0). However it should also allow a single negative number: -1. After some trial and error I came up with this: ^(-[1]|[1-9]+)$ This allows negative 1 and any number. But being new to regex I'm confused about how to cap the number range to 2048? Finally, I'm aware that regex is not always recommended. But in this case where there are several conditions(only numbers within a range, no special characters or

Replace Polish characteres with standard ascii equivalent

蓝咒 提交于 2021-01-29 17:47:11
问题 Basically, I have a huge amount of files and many of them contain polish letters like 'ł, ż, ź, ó, ń' etc. in their filename. What I want to reach is somehow change this polish letter to standard ascii character. (So for example ż => z, ń => n). The files are located on the server with Linux Debian Squeezee. What should I use and how to achieve the final effect? 回答1: You put a PHP tag to your question, so my answer will consider that. There is a question similiar to yours. Convert national

Regex for polynomial expression

一个人想着一个人 提交于 2021-01-29 17:45:55
问题 I have a string that I hope is a polynomial expression, something like "2x^2-3x+1 . I want to use a regex to group each term in the expression. I currently have "^(-?\d?x(\^\d)?)+" . I'm trying to capture a term as an optional minus sign, then a number, then x, then an optional exponent, which should be of the form "^someNumber". So for my above polynomial, I'd want group 1 to be "2x^2" , group 2 to be "-3x" and group 3 to be "+1" . Firstly, if I have (someGroupExpression)+ , will this

Why doesn't this simple RegEx work with sed?

旧时模样 提交于 2021-01-29 17:41:50
问题 This is a really simple RegEx that isn't working, and I can't figure out why. According to this, it should work. I'm on a Mac (OS X 10.8.2). script.sh #!/bin/bash ZIP="software-1.3-licensetypeone.zip" VERSION=$(sed 's/software-//g;s/-(licensetypeone|licensetypetwo).zip//g' <<< $ZIP) echo $VERSION terminal $ sh script.sh 1.3-licensetypeone.zip 回答1: Looking at the regex documentation for OS X 10.7.4 (but should apply to OP's 10.8.2), it is mentioned in the last paragraph that Obsolete (basic)

Ignoring invisible characters in RegEx

北战南征 提交于 2021-01-29 16:59:38
问题 I've run into a bit of a conundrum. I am currently trying to build a regex to filter out some particularly nasty scam emails. I'm sure you've seen them before, using a data dump from a compromised website to threaten to reveal intimate videos. That's all well and good, except I noticed while testing the regex that some of these messages insert special invisible characters in the middle of words. Like you might see here (I've found it especially hard to find a place that keeps these special

JavaScript Regex: How to split html string into array of html elements and text nodes?

大兔子大兔子 提交于 2021-01-29 16:08:17
问题 For example, this html string: Lorem <b>ipsum</b> dolor <span class="abc">sit</span> amet,<br/>consectetur <input value="ok"/> adipiscing elit. into this array: [ 'Lorem ', '<b>ipsum</b>', ' dolor ', '<span class="abc">sit</span>', ' amet,', '<br/>', 'consectetur ', '<input value="ok"/>', 'adipiscing elit.' ] Here is the example of html elements match: const pattern = /<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)<\/\1>|<([A-Z][A-Z0-9]*).*?\/>/gi; let html = 'Lorem <b>ipsum</b> dolor <span class="abc">sit<

nutch 1.16 skips file:/directory styled links in file system crawl

折月煮酒 提交于 2021-01-29 16:01:20
问题 I am trying to run nutch as a crawler over some local directories using examples taken from both the main tutorial (https://cwiki.apache.org/confluence/display/nutch/FAQ#FAQ-HowdoIindexmylocalfilesystem?) as well as from other sources. Nutch is perfectly able to crawl the web no problem, but for some reason it refuses to scan local directories. My configuration files are as follows: regex-urlfilter: # Each non-comment, non-blank line contains a regular expression # prefixed by '+' or '-'. The

Regex - Why doesn't this pattern work when using the new RegExp method?

一世执手 提交于 2021-01-29 15:52:31
问题 I'm searching this string for an the 'invite=XXXX' part. I am using a capturing group to extract the value between '=' and ';'. When I use the first regex method it works, but when I use the second it doesn't. Why is this? var string = "path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; invite=1323969929057; path=/; expires=Sat, 14 Jan 2012 17:25:29 GMT;"; // first method var regex1 = /invite=(\w+)/; var regexMatch1 = string.match(regex1); // second method var regex2 = new RegExp("/invite=(\w+)/"

How to detect text language with jQuery and XRegExp to display mixed RTL and LTR text correctly

南笙酒味 提交于 2021-01-29 14:43:30
问题 I'm trying to display a Twitter feed in a WordPress site. My client tweets in English and in Arabic and sometimes in a combination of the two languages. I need to detect the language and add the class 'rtl' to Arabic tweets and also those tweets where the content is predominately in Arabic. I'm using a plugin which strips the Twitter iso_language_code metadata. When attempting this on a previous development site a few years ago, I remember successfully using a variation of Tristan's solution