Regex to match only the first line?

that’s sounds more like a job for the filehandle buffer. You should be able to match the first line with: /^(.*)$/m (as always, this is PCRE syntax) the /m modifier makes ^ and $ match embedded newlines. Since there’s no /g modifier, it will just process the first occurrence, which is the first line, and … Read more

Javascript regex to validate IPv4 and IPv6 address, no hostnames

I had the exact same necessity, so I adapted the regex from Daniel’s great answer (which is the most accurate I was able to find) to NOT validate hostnames. Here it is: var expression = /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/; if (expression.test(valueToTest)) { // good IP } else { // bad IP } I forked Daniel’s original JSFiddle to … Read more

How do you capture a group with regex?

Here’s a code example that demonstrates capturing multiple groups. You can see that group ‘0’ is the whole match, and subsequent groups are the parts within parentheses. Note that this will only capture the first match in the source string. Here’s a version that captures multiple groups in multiple matches. #include <stdio.h> #include <string.h> #include … Read more

Filter by Regex in JQ

If you tacked the following filter onto the one you already have, then you’d get the output shown below: map(select(.Address | test(“^[0-9]”))) Output: [ { “Address”: “1 Bridge Rd” } ] For robustness, you might like to consider adding ? after the test: map(select(.Address | test(“^[0-9]”)?)) Or, you could combine the two calls to map … Read more

Using JavaScript to check whether a string contains Japanese characters (including kanji)

Check whether this works or not. I found this website that seems to list all the characters in Unicode that might be used in Japanese text. The corresponding regex (for single character) would be: /[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]/ ————-_____________————-_____________————-_____________ Punctuation Hiragana Katakana Full-width CJK CJK Ext. A Roman/ (Common & (Rare) Half-width Uncommon) Katakana The ranges are (as … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)