Skip to content
Advertisement

Tag: regex

JavaScript regex get number after string

After coming to the shocking realization that regular expressions in JavaScript are somewhat different from the ones in PCE, I am stuck with the following. In php I extract a number after x: In JavaScript the same regex doesn’t work, due to invalid group resulting from the capturing parenthesis difference. So I am trying to achieve the same trivial functionality,

Get ID from “ tag using a combined `.match` call

I have a string like this And I just want to get the id value which is test_name. I use this code: Is there any other ways to combine two match calls into one? Answer Use capturing group. If the regular expression contain capturing group, String.prototype.match will return an array which contains whole matched string and captured groups: You can

replace newline string literal – ‘n’ in javascript

I have string literal, n in a variable. I am trying to replace it with empty string. But it doesn’t work. value evaluates to the string literal – n. I expect no output from console.log. But it prints Empty line followed by a backward slash (for some reason, stack overflow has trimmed the empty line in above output). Note, this

Javascript Pangram Regex

I am trying to write a REGEX to test for a PANGRAM. I can do it the traditional way, but cannot seem to solve it for more than 90% of my tests with a regular expression. Input: string Output: true || false Test Results so far. 6/10 /([a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z, s]+)/i 6/10 /[a-z]{1}/i 6/10 /[a-z]/i 6/10 /[a-z]+/i 9/10 /a?b?c?d?e?f?g?h?i?j?k?l?m?n?o?p?q?r?s?t?u?v?w?x?y?z/i only failed against

Regex bold characters using *

If I have text like: I need to bold *this* text and *that* text. I need to bold this text and that text. I need to convert both to <b>this</b> and <b>that</b>. This is not doing what I want for 2 or more matches. It’s doing this instead: I need to bold this text and that text and this text

Convert javascript object camelCase keys to underscore_case

I want to be able to pass any javascript object containing camelCase keys through a method and return an object with underscore_case keys, mapped to the same values. So, I have this: And I want a method to output this: What’s the fastest way to write a method that takes any object with any number of key/value pairs and outputs

Javascript regex matching at least one letter or number?

What would be the JavaScript regex to match a string with at least one letter or number? This should require at least one alphanumeric character (at least one letter OR at least one number). Answer In general, a pattern matching any string that contains an alphanumeric char is However, a regex requirement like this is usually set up with a

How to parse and capture any measurement unit

In my application, users can customize measurement units, so if they want to work in decimeters instead of inches or in full-turns instead of degrees, they can. However, I need a way to parse a string containing multiple values and units, such as 1′ 2″ 3/8. I’ve seen a few regular expressions on SO and didn’t find any which matched

how to restrict special characters and ( /,*,+) only

We have one text Field.We know how to restrict special characters.But We need Allow alphabet and Numbers and hyphen(-) only.No need Sepcial characters but except (-) . Give me any idea. Mycode: If we tried this code it’s restrict spectal charecters but it’s allow -,/,+ Please guide me only allow number and alphabet and hyphen only Answer replace this section:

Need a RegExp to filter out all but one decimal point

I’m using the following code to negate the characters in the regexp. By checking the inverse, I can determine if the value entered is correctly formatted. Essentially, any digit can be allowed but only one decimal point (placed anywhere in the string.) The way I have it now, it catches all numerals, but allows for multiple decimal points (creating invalid

Advertisement