Questions tagged [rubular]

A Ruby-based regular expression editor and tester.

A Powerful and most efficient Domain for testing Regular Expressions.

Website: http://rubular.com/

66 questions
67
votes
5 answers

Regex, how to match multiple lines?

I'm trying to match the From line all the way to the end of the Subject line in the following: .... From: XXXXXX Date: Tue, 8 Mar 2011 10:52:42 -0800 To: XXXXXXX Subject: XXXXXXX .... So far I have: /From:.*Date:.*To:.*Subject/m But that doesn't…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
13
votes
5 answers

How to check validity of closed brackets, parentheses or brackets in Ruby

Write a method 'valid_string?' that accepts a string. It returns true if the brackets, parentheses, and curly braces close correctly. It returns false otherwise. valid_string?("[ ]") # returns true valid_string?("[ ") …
goldenpath
  • 137
  • 1
  • 4
4
votes
2 answers

Regex lookahead/lookbehind comments

I have a snippet from a config file that I need to be able to match the specified string quote contents, but only when they're not commented out, here's my current regex: (?
bruchowski
  • 5,043
  • 7
  • 30
  • 46
3
votes
1 answer

Regex URL validation in Ruby

I have the following ruby code in a model: if privacy_policy_link.match(/#{domain}($|\/$)/) errors.add(:privacy_policy_link, 'Link to a specific privacy policy page on your site instead of your homepage.') end This worked until a user tried to…
pixelcandy
  • 109
  • 6
3
votes
2 answers

Ruby Regex Different from Rubular

I'm trying the same super simple regex on Rubular.com and my VM Linux with Ruby 1.9.2 I dont' know why I'm getting different outputs: VM: my_str = "Madam Anita" puts my_str[/\w/] this Outputs: Madam on Rubular it outputs: MadamAnita Rubular:…
frenesim
  • 703
  • 9
  • 10
2
votes
3 answers

Regex to match a String with optional Conditions

Possible Duplicate: How do I make part of a regular expression optional in Ruby? I'm trying to build a regular expression with rubular to match: On Feb 23, 2011, at 10:22 , James Bond wrote: OR On Feb 23, 2011, at 10:22 AM , James Bond…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
2
votes
1 answer

How to get Match Groups in ruby like Rubular without spliting the string

How does Rubular (Example) get the match groups? /regex(? .*)/.match('some long string') match method (in example) only returns the first match. scan method returns an array without named captures. What is the best way to get an array of…
Mo3z
  • 2,138
  • 7
  • 21
  • 29
2
votes
2 answers

Looking for a way to match any domain email ending with certain tld

New to regex and ruby was looking for a way to match any domain ending with certain tld I have the following emails: jane.doe@navy.mil barak.obama@whitehouse.gov john.doe@usa.army.mil family@example.com I am trying to write a regular expression…
adbarads
  • 1,253
  • 2
  • 20
  • 43
2
votes
2 answers

regular expression ruby phone number

I'm trying to figure out how to write my own regex. I made a list of viable phone numbers and non-viable ones and trying to make sure the viable ones are included but I can't figure out how to finish it up. Allowed list 0665363636 // 06 65 36 36 36…
Martijn Kerckhaert
  • 494
  • 1
  • 6
  • 21
2
votes
3 answers

How to access the various occurences of the same match group in Ruby Regular expressions ?

I have a regular expression which has multiple matches. I figured out that $1 , $2 etc .. can be used to access the matched groups. But how to access the multiple occurences of the same matched group ? Please take a look at the rubular page below.…
Pradep
  • 1,874
  • 5
  • 21
  • 31
1
vote
1 answer

Extract using regex

I'm new to Ruby, Regex and Stackoverflow. xD Here's my problem: I want to use regex to extract phrases consisting of consecutive words with standard ASCII characters apart from the others in Vietnamese texts. In another word, phrases with \w…
Thiem Nguyen
  • 6,345
  • 7
  • 30
  • 50
1
vote
1 answer

Rubular versus javascript regexp capture groups

Noticed a difference between what Rubular.com and Javascript regexes: 'catdogdogcatdog'.match(/cat(dog)/g); // JS returns ['catdog', 'catdog'] I expected to capture 'dog' twice but instead I get 'catdog' twice. Rubular captures 'dog' twice as…
Roxicus
  • 109
  • 1
  • 7
1
vote
2 answers

Rubular Expression

How can we extract the words from a string in rubular expression? $0Public$robotics00$india0$000facebook If we want to extract the words Public robotics india facebook from the above string, how can we? I am using ([^0$]), but it is giving the…
Tanish Gupta
  • 400
  • 2
  • 8
  • 20
1
vote
1 answer

Regex to handle all Multiline exception in rubular fluentd

I designed the regex to match the all multiline exception or warning message field for fluentd parser in rubular format as below (SLF4J:\s.*|[a-zA-z_]*\..*\.*\s.*\s.*|Caused\sby:\s|\s+at\s.*|\s+\.\.\. (\d)+ more) It matches unnecessary fields. I…
SKumar
  • 13
  • 4
1
vote
0 answers

JavaScript Regex expression producing unexpected results when run in console vs in rubular

I have a string of addresses: let addr3 = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432,54 Holy Grail Street Niagara Town ZP 32908,3200 Main Rd. Bern AE 56210,1 Gordon…
Dog
  • 2,726
  • 7
  • 29
  • 66
1
2 3 4 5