Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6245881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:35:17+00:00 2026-05-24T12:35:17+00:00

regex = Regexp.new(/param\s*=\s*([^\|]*)/) regex.match(text).to_s link = $1 link.strip! espesially code like this: regex =

  • 0
regex = Regexp.new(/param\s*=\s*([^\|]*)/)
regex.match(text).to_s
link = $1
link.strip!

espesially code like this:

regex = Regexp.new(/regex/)
regex.match(text).to_s
match = $1

I even tried gsub misuse, but it is not The Right Way®

match = gsub Regexp.new(/.*(regex).*/, '\1')
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:35:18+00:00Added an answer on May 24, 2026 at 12:35 pm

    So given a string like this:

    s = "blah blah param=pancakes|eggs"
    

    You want to extract just "pancakes", right? If so, then:

    you_want = s[/param\s*=\s*([^|]+)/, 1]
    

    The \s* will eat up any leading whitespace so half of your strip! is not needed. If you don’t want any whitespace inside the extracted value at all then:

    you_want = s[/param\s*=\s*([^|\s]+)/, 1]
    

    If you just want to strip off the trailing whitespace, then add an rstrip:

    you_want = s[/param\s*=\s*([^|]*)/, 1].rstrip
    

    This one will throw an exception if s doesn’t your regular expression though.

    See String#[] for further details.

    I’ve also changed your []* to []+ to avoid matching nothing at all. Also, you don’t have to escape most metacharacters inside a character class (see Tim’s comment) so just | is fine inside a character class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this: jQuery.validator.addMethod(regex2, function(value, element, param) { return value.match(new RegExp(. + param +
I am kinda new to this Regex thing. When analyzing some code I frequently
Consider this code: import java.util.regex.*; public class Pattern3 { /** * @param args the
I am entirely new to regex, and am trying to use it to match
I'm new to using regexp, can someone give me the regexp that will strip
How can I fix this? REGEX: //REGEX $match_expression = '/Rt..tt<\/td> <td>(.*)<\/td>/'; preg_match($match_expression,$text,$matches1); $final =
How do you match more than one pattern in vbscript? Set regEx = New
I have, for example, markup like this <div id=content> <p>Here is some wonderful text,
Currently we're using javascript new RegExp('#[^,#=!\s][^,#=!\s]*') (see [1]) and it mostly works, except that
I am a Javascript Junkie and wishing to test around some codes. new RegExp(user=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.