Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default Help with Regexp, please

Hi,

The regular expression (\d{15,16}) matches a substring in a cell. I
want to extract the remaining part of the cell ie. from the character
after the matched substring till the end of the string in the cell
using a regular expression.

Is it possible to do this?

Thanks in advance for the help.

Regards,
Raj

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Help with Regexp, please

On Sat, 1 May 2010 05:39:32 -0700 (PDT), Raj wrote:

Hi,

The regular expression (\d{15,16}) matches a substring in a cell. I
want to extract the remaining part of the cell ie. from the character
after the matched substring till the end of the string in the cell
using a regular expression.

Is it possible to do this?

Thanks in advance for the help.

Regards,
Raj


(\d{15,16})([\s\S]*)

will capture everything in the cell and after your "match" into Group 2




--ron
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Help with Regexp, please

On Sat, 01 May 2010 14:47:46 -0400, Ron Rosenfeld
wrote:

On Sat, 1 May 2010 05:39:32 -0700 (PDT), Raj wrote:

Hi,

The regular expression (\d{15,16}) matches a substring in a cell. I
want to extract the remaining part of the cell ie. from the character
after the matched substring till the end of the string in the cell
using a regular expression.

Is it possible to do this?

Thanks in advance for the help.

Regards,
Raj


(\d{15,16})([\s\S]*)

will capture everything in the cell and after your "match" into Group 2




--ron


Can't [\s\S] be replaced by . like this
(\d{15,16})(.*)

Lars-Åke

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default Help with Regexp, please

To clarify, the regex should return " Raffles Traders" from the string
below:

NRK2D 986123456789312 Raffles Traders

The regex (\d{15,16})([\s\S]*) is returning "986123456789312 Raffles
Traders"

Regards,
Raj



On May 2, 12:08*am, Lars-Åke Aspelin wrote:
On Sat, 01 May 2010 14:47:46 -0400, Ron Rosenfeld



wrote:
On Sat, 1 May 2010 05:39:32 -0700 (PDT), Raj wrote:


Hi,


The regular expression (\d{15,16}) matches a substring in a cell. I
want to extract the remaining part of the cell ie. from the character
after the matched substring till the end of the string in the cell
using a regular expression.


Is it possible to do this?


Thanks in advance for the help.


Regards,
Raj


(\d{15,16})([\s\S]*)


will capture everything in the cell and after your "match" into Group 2


--ron


Can't [\s\S] be replaced by . like this
(\d{15,16})(.*)

Lars-Åke


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Help with Regexp, please

Just in case you are interested, here is some non-RegEx code that finds the
same part of your text (the result is returned in the variable named
TailEnd)...

Text = "NRK2D 986123456789312 Raffles Traders"
For X = 1 To Len(Text)
If Mid(Text, X, 15) Like String(15, "#") Then
TailEnd = Mid(Text, X + 15)
Exit For
End If
Next

--
Rick (MVP - Excel)



"Raj" wrote in message
...
To clarify, the regex should return " Raffles Traders" from the string
below:

NRK2D 986123456789312 Raffles Traders

The regex (\d{15,16})([\s\S]*) is returning "986123456789312 Raffles
Traders"

Regards,
Raj



On May 2, 12:08 am, Lars-Åke Aspelin wrote:
On Sat, 01 May 2010 14:47:46 -0400, Ron Rosenfeld



wrote:
On Sat, 1 May 2010 05:39:32 -0700 (PDT), Raj wrote:


Hi,


The regular expression (\d{15,16}) matches a substring in a cell. I
want to extract the remaining part of the cell ie. from the character
after the matched substring till the end of the string in the cell
using a regular expression.


Is it possible to do this?


Thanks in advance for the help.


Regards,
Raj


(\d{15,16})([\s\S]*)


will capture everything in the cell and after your "match" into Group 2


--ron


Can't [\s\S] be replaced by . like this
(\d{15,16})(.*)

Lars-Åke




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Help with Regexp, please

On Sat, 1 May 2010 17:32:04 -0400, "Rick Rothstein"
wrote:

Just in case you are interested, here is some non-RegEx code that finds the
same part of your text (the result is returned in the variable named
TailEnd)...

Text = "NRK2D 986123456789312 Raffles Traders"
For X = 1 To Len(Text)
If Mid(Text, X, 15) Like String(15, "#") Then
TailEnd = Mid(Text, X + 15)
Exit For
End If
Next

--
Rick (MVP - Excel)


Rick,

The OP's original regex (\d{15,16}) will capture the first 15 *OR 16* digit
string into capture group 1. So when the *rest* of the string is returned, it
will omit digit 16 if present.

Your code will return the 16th digit, if present, as a part of "TailEnd"
--ron
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Help with Regexp, please

On Sat, 1 May 2010 13:41:03 -0700 (PDT), Raj wrote:

To clarify, the regex should return " Raffles Traders" from the string
below:

NRK2D 986123456789312 Raffles Traders

The regex (\d{15,16})([\s\S]*) is returning "986123456789312 Raffles
Traders"

Regards,
Raj


Obviously, you are not doing what I suggested which was to return the *SECOND*
matching group. You are returning the ENTIRE match. Here's an example as to
returning the *SECOND* match using VBA:

===============================
Option Explicit
Function Part2(s As String) As String
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = "(\d{15,16})([\s\S]*)"
If re.test(s) = True Then
Set mc = re.Execute(s)
Part2 = mc(0).submatches(1)
End If
End Function
==================================
--ron
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Help with Regexp, please

On Sat, 01 May 2010 21:08:01 +0200, Lars-Åke Aspelin
wrote:

Can't [\s\S] be replaced by . like this
(\d{15,16})(.*)

Lars-Åke


Your suggestion will work IF and ONLY IF there are no line feeds or carriage
returns in the cell. In some flavors, there is an option to have Dot match
newline, but such does not exist in VBA (or Javascript).

If the OP, rather than wanting to extract everything to " ... the end of the
string in the cell" only wanted to extract everything to the end of the line,
and ignore anything in the cell after a newline character, then (.*) would be
appropriate.
--ron
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default Help with Regexp, please

I have made another post before Ron's last post. I have explained the
requirement with an example.

Regards,
Raj



On May 2, 1:43*am, Ron Rosenfeld wrote:
On Sat, 01 May 2010 21:08:01 +0200, Lars-Åke Aspelin
wrote:

Can't [\s\S] be replaced by . like this
(\d{15,16})(.*)


Lars-Åke


Your suggestion will work IF and ONLY IF there are no line feeds or carriage
returns in the cell. *In some flavors, there is an option to have Dot match
newline, but such does not exist in VBA (or Javascript).

If the OP, rather than wanting to extract everything to " ... the end of the
string in the cell" *only wanted to extract everything to the end of the line,
and ignore anything in the cell after a newline character, then (.*) would be
appropriate.
--ron


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
RegExp not matching what I want Phil Hibbs Excel Programming 9 April 21st 10 03:47 PM
RegExp & VB Noob Qs Ron Rosenfeld Excel Programming 2 June 28th 08 12:47 AM
RegExp Arshavir Grigorian Excel Programming 2 March 13th 08 12:55 AM
RegExp information Alain R. Excel Programming 1 February 18th 08 02:56 PM
RegExp - String in VBA MSK Excel Programming 0 July 24th 07 02:50 PM


All times are GMT +1. The time now is 12:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"