+ Reply to Thread
Results 1 to 17 of 17

Instr function withing Regex

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Instr function withing Regex

    Hi,

    i want to get long as first matched character from regex object.

    Code is described here:

    https://www.excelforum.com/excel-pro...-function.html

    Please Login or Register  to view this content.
    so i would like to get instr within regex so get long from first character from matched string (something like instr(1,textString ,"T_DATACENTERSSOURCE") but with exact match).
    How can i do this?

    Jacek

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Instr function withing Regex

    Need to escape meta charcter
    Please Login or Register  to view this content.
    Last edited by jindon; 05-03-2019 at 01:46 AM.

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Instr function withing Regex

    jindon,

    thank you very much.
    i changed a PatternToFind (i do not need indirect here only quotation mark)

    Please Login or Register  to view this content.
    and this is working.

    But i do not understand what you are doing jindon?

    "?!(\[.*)" here you are excluding sign [ ? why? please explain this expression.

    I found something like this in internet:

    Please Login or Register  to view this content.
    but this is returning 1 as result - i do not know why?
    It should return 74 because there is a first occurrence of PatternToFind there.

    Best
    Jacek
    Last edited by jaryszek; 05-03-2019 at 01:45 AM.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Instr function withing Regex

    That was my mistake.

    As I mentioned in you previous thread, if you change PatternTo Find to "T_DATACENTERSSOURCE[" it will be all solved.
    However you need to eacape [ by adding \ means PatternTo Find = "T_DATACENTERSSOURCE\[", so that my previous post should be ignored.

    Anyway, better the add escape charcter(s) within a function.
    Last edited by jindon; 05-03-2019 at 01:52 AM.

  5. #5
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Instr function withing Regex

    jindon,

    thank you. Sorry it is hard to understand. And you are saving my *** right now.
    but if i will have "T_DATACENTERSSOURCE" instead of "T_DATACENTERSSOURCE[LOCATIONID]" it will not work?:

    textString = "=INDEX(INDIRECT(""T_DATACENTERSSOURCE[DATACENTER]""),MATCH([@RegionName],T_DATACENTERSSOURCE),0))"

    Best wishes for you,
    Jacek

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Instr function withing Regex

    Meta characters

    ^ | $ ( ) [ ] { } + * ? . \ -

    When these characters are used as a plain string in the PATTERN, it should be escaped by adding \ like

    "T_DATACENTERSSOURCE\[LOCATIONID\]"

    otherwise, it will be treated as a meta character as [LOCATION], means any one character from the character set.

    You know what I mean?
    Last edited by jindon; 05-03-2019 at 02:08 AM.

  7. #7
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Instr function withing Regex

    yes,

    thank you very much. But [LocationID] i will skip from pattern, it will be only table name. I will have only "T_DATACENTERSSOURCE".

    Please Login or Register  to view this content.
    Without any special/meta characters but One special character is quotation mark in front of string.

    1. So i am trying to find:

    Screenshot_13.png

    i do not know why also "," is taken ? i do not want to have this included.
    And this is not exact match.

    2. If i will change it to exact table name like "T_DATACENTERS" it will also work, and it shouldn't.

    Screenshot_14.png

    Please help,
    Jacek
    Last edited by jaryszek; 05-03-2019 at 02:14 AM.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Instr function withing Regex

    Do you mean
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    You just need to double.

  9. #9
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Instr function withing Regex

    Ok thank you very much!

    This is not what i meant but this is perhaps solving the problem, can you please confirm?

    Please Login or Register  to view this content.
    it will find exact match of string which is not preceded by quotation mark, it is true?

    It seems that this is working.

    the only problem here is that i am getting "," included. Why?

    Jacek
    Attached Images Attached Images
    Last edited by jaryszek; 05-03-2019 at 02:35 AM.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Instr function withing Regex

    Ahh, you don't want the quotation mark ahead, I thought other way.

    Yeah, it should match to ",T_DATACENTERSSOURCE" part.

  11. #11
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Instr function withing Regex

    thank you jindon!

    i can not add you reputatin unfortunately because i added to much.

    Ok, i do not want to have ",T_DATACENTERSSOURCE", only "T_DATACENTERSSOURCE". how to do this?

    Jacek

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Instr function withing Regex

    Only the way you can do it to add () for back reference and get it by submatches, like
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Instr function withing Regex

    Thank you

    or in this function can i use???

    Please Login or Register  to view this content.
    so +2 will give me the exact start number of string?

    Jacek

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Instr function withing Regex

    Should be OK.

  15. #15
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Instr function withing Regex

    thank you!!

    Jacek

  16. #16
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Instr function withing Regex

    Why would you have MATCH([@RegionName],T_DATACENTERSSOURCE) when MATCH requires a single row or column, not a table?
    Rory

  17. #17
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Instr function withing Regex

    thank you Rory,

    this was just an example.

    Jacek

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Instr with RegEx - Runtime error 5017 (RegEx Code provided)
    By dluhut in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2018, 05:02 PM
  2. [SOLVED] help with a function using Regex
    By Pancho3 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-24-2016, 09:22 PM
  3. Passing a RegEx to a function
    By amphinomos in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-31-2014, 06:12 AM
  4. Can I place a function call withing SQL Statements?
    By ions in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-15-2008, 10:24 PM
  5. [SOLVED] InStr Function
    By zoot in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2006, 10:55 PM
  6. Which function to check any value existed withing a list?
    By Eric in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-30-2005, 08:40 PM
  7. Replies: 1
    Last Post: 12-30-2005, 08:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1