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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:57:19+00:00 2026-06-03T00:57:19+00:00

Quick RegExp problem (i hope). I need to identify a sub string from any

  • 0

Quick RegExp problem (i hope).

I need to identify a sub string from any string based on a regular expression.

For Example, take the following strings:

"Blogs, Joe (S0003-000292).html"
"bla bla bla S0003-000292 & so on"
"RE: S0003-000292"

I need to extract the ‘S0003-000292’ portion (or flag exception if not found).

As for what i have tried, well, i’ve written a rough pattern to identify S0000-000000:

^\(S[0-9]{4}-[0-9]{6}\)$

And i have tried testing for it as follows:

Dim regex As New Regex("Blogs, Joe (S0003-000292) Lorem Ipsum!")
Dim match As Match = regex.Match("^S[0-9]{4}-[0-9]{6}$")

If match.Success Then
    console.writeline "Found: " & match.Value
Else
    console.writeline "Not Found"
End If

However, this always results in Not Found.

So, 2 questions really, what is wrong with my pattern & how can I use a revised pattern to extract the sub string?

(Working with .net 2)

EDIT: stema pointed me in the right direction (i.e. to drop the ^ and $) – however that did not solve the problem, my main problem was that i had defined the string in the RegEx contructor instead of the pattern – swapped these over and it worked fine (i blame lack of caffine):

Dim regex As New Regex("S[0-9]{4}-[0-9]{6}")
Dim match As Match = regex.Match("Joe, Blogs (S0003-000292).html")

If match.Success = True Then
    console.writeline "Found: " & match.Value
Else
    console.writeline "Not Found"
End If
  • 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-03T00:57:21+00:00Added an answer on June 3, 2026 at 12:57 am

    You have anchors in place that prevents your pattern from matching

    ^\(S[0-9]{4}-[0-9]{6}\)$
    ^                      ^
    

    ^ is matching the start of the string

    $ is matching the end of the string

    and since there is other stuff before and after the part you want to match, your pattern will not match. Just remove those anchors and it should be fine.

    Or use word boundaries instead

    \bS[0-9]{4}-[0-9]{6}\b
    

    \b will match if there is a “non-word” character (non a letter or a digit) before and after your pattern.

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

Sidebar

Related Questions

Need quick help with regexp, to search a string for blah blah blah price
I need a quick regexp for validating that a string is a valid .au
just need a quick help for solving this problem. I want to strip all
I'm writing a quick PHP page, and I need to ignore any Strings with
I need a simple regexp for php preg_replace: Input: Quick brown :no: fox etc
I had a problem and whipped up a quick solution: fade-in and fade-out a
I'm completely incapable of regular expressions, and so I need some help with a
Can anyone help me with a quick regex problem? I have the following HTML:
I need to separate out a bunch of image urls from a document in
quick question: my pattern is an svg string and it looks like l 5

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.