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 8202377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:09:43+00:00 2026-06-07T07:09:43+00:00

Possible Duplicate: R regular expression: http matching I’m working to capture URLs from a

  • 0

Possible Duplicate:
R regular expression: http matching

I’m working to capture URLs from a chunk of source code using regex.

The URL’s follow a pattern and are in the following form:

  • http://www.google.com/…./1-1,1″
  • http://www.google.com/…./1-2,2″
  • http://www.google.com/…./1-20,20″

so far I can get to the url using the following code:

pattern = paste("1-", 1:20,",", 1:20, "\"", sep="")

this gives me a vector of:

  • 1-1,1
  • 1-2,2
  • …..
  • 1-20,20

then I can use these vectors to give me a position or the URLs inside the soure code .

Let’s say for example that the whole source code is simply: “http://www.google.com/word/1-1,1>”

`regexpr("1-1,1", test1k, TRUE)`

gives me:

[1] 28 attr(,”match.length”) [1] 5

this means that the pattern 1-1,1 starts at length 28. Given this information, how would I select the whole URL starting at “http://ww…” until the end “1-1,1>”.

I guess what I’m asking is, give the position 28, is there a function to select the nearest “http://” string going backwards (this marks the start of the URL). Similarly, given the position 28, is there a way to select the nearest “>” character going forward (this marks the end of the URL).

  • 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-06-07T07:09:44+00:00Added an answer on June 7, 2026 at 7:09 am

    Rather than creating all possible combinations, just use the \\d character, which will match any digit. For example:

     regexpr("1-\\d+,\\d+", test1k, TRUE)
    

    To select the whole URL, you want to start the regular expression with “http”, and then have it continue until the first time this pattern is matched. One simple way is:

    regexpr("http.*?1-\\d+,\\d+", test1k, TRUE)
    

    The .* pattern has three parts. The . matches any character, the * means “any number of that character, and the ? means that it’s not greedy (otherwise, this will take up the entire string from the first http to the last 1-\\d+,\\d+.

    For example:

    > regexpr("http.*1-?\\d+,\\d+", "The URL that you are looking for is http://www.google.com/word/1-1,1", TRUE)
    [1] 37
    attr(,"match.length")
    [1] 32
    attr(,"useBytes")
    [1] TRUE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Regular expression: match all words except I need your help for using
Possible Duplicate: how can i validate a url in javascript using regular expression I
Possible Duplicate: Using C# regular expressions to remove HTML tags Extract Content from Div
Possible Duplicate: Using regular expression within a stored procedure I need to validate a
Possible Duplicate: Python Regular Expression Matching: ## ## I already asked this question, but
Possible Duplicate: What is the best regular expression for validating email addresses? I'm using
Possible Duplicate: Interesting test of Javascript RegExp Regular expression test can't decide between true
Possible Duplicate: Regex to match URL Is there a regular expression to return a
Possible Duplicate: How to escape text for regular expression in Java Is there a
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP

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.