Consulting

Results 1 to 20 of 20

Thread: Regular Express

  1. #1
    VBAX Newbie
    Joined
    May 2008
    Posts
    4
    Location

    Regular Expression

    Hi Friends,

    I want a VBA Macro to find the value of the string ("100 X 250 X 500 mms") is matching with a pattern.if it is not matching with the pattern is it possible to detect in which part it is not matching and how to correct it?

    For Example - > Original String Value is - > 100 X 250 X 500 mms

    Pattern Matching using RegEx is some thing like this - > ^\d{1,4}\ \X\d{1,4}\ \X\d{1,4}\ \[a-z] {1,3}

    it is easier to match the string with the pattern and find out whether the string is correct or not.

    If the value of the string is not correct then how to find which part is wrong and how to correct it? (Is there any specific object and properties are there in RegEx)


    If there is some other string (For Ex. \or ! or * etc.) other than numbers and characters and space it should give a message "Invalid Stirng".

    Is is possible to find and replace using RegEx?

    If the string contains proper value but small mistakes like - > this "100X250X500 mms" or
    100X 250 X500 mms occured then it should detect the mistake and correct the value using VBA Macro.

    Kindly reply to this question ASAP.

    Thanks and Regards,
    Mahesh.
    Last edited by ishwaar; 05-11-2008 at 08:54 AM. Reason: Need the macro part not the normal Find and Replace method

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That bit easy should it be as you describe, but what if there is something else in there, some rogue string? And is it 3 @ 3digit numbers only around the Xs.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Just use excels find and replace, from the toolbar EDIT, FIND click replace in find enter x in replace press space bar then x then space bar now click replace all, do the same for mms.

    Easy fix!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    VBAX Newbie
    Joined
    May 2008
    Posts
    4
    Location
    Hi Friends,

    I want a VBA Macro to find the value of the string ("100 X 250 X 500 mms") is matching with a pattern.if it is not matching with the pattern is it possible to detect in which part it is not matching and how to correct it?

    For Example - > Original String Value is - > 100 X 250 X 500 mms

    Pattern Matching using RegEx is some thing like this - > ^\d{1,4}\ \X\d{1,4}\ \X\d{1,4}\ \[a-z] {1,3}

    it is easier to match the string with the pattern and find out whether the string is correct or not.

    If the value of the string is not correct then how to find which part is wrong and how to correct it? (Is there any specific object and properties are there in RegEx)


    If there is some other string (For Ex. \or ! or * etc.) other than numbers and characters and space it should give a message "Invalid Stirng".

    Is is possible to find and replace using RegEx?

    If the string contains proper value but small mistakes like - > this "100X250X500 mms" or
    100X 250 X500 mms occured then it should detect the mistake and correct the value using VBA Macro.

    Kindly reply to this question ASAP.

    Thanks and Regards,
    Mahesh.

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Mahesh,
    Wondering why you just reposted your original question ver batim instead of trying to answer some of the legitimate questions that were asked after you posted the first one. This shows disrespect to those from whom you are seeking help.

    In addition I would add that requesting answers ASAP will likely turn people off to your problem. Everyones questions are important and if you are in a crunch for time then maybe you should consider hiring someone here as a consultant. Click here to find out how.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Newbie
    Joined
    May 2008
    Posts
    4
    Location
    Hi,

    Sorry for the inconvenience.Instead of replying to the XLD's question I have reposted it.

    Thanks and Regards,
    Mahesh

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    We know that, and it doesn't help one iota, so you have wasted your post, Steve's reminder, and this blast from me.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I didn't say it was an inconvenience, I said it was disrespectful to those from whom you seek help.

    How can reposting the original question help us understand your problem? You imply that we either didn't read it or that it contains the information required to answer your question which it obviously does not.

    If you need help with this then we need some clarification.

    Thanks for your cooperation.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    I still stand with.....use the "Find & Replace" its far more efficient!, you can record all the actions needed to space the string out correctly (4 find and replaces i think), you are wanting to use a sledgehammer to crack a nut!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  10. #10
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Mahesh

    You could probably use RegExp to extract the numbers but then you would probably need to use standard VBA functions to reconstruct to give the correct string.

    Simon

    Have you ever used regular expressions?

    I think you might find they are a lot more powerful than find and replace.

    And with find and replace you'd have to consider all possible combinations.

  11. #11
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Quote Originally Posted by Norie
    Simon
    Have you ever used regular expressions?
    I think you might find they are a lot more powerful than find and replace.
    And with find and replace you'd have to consider all possible combinations.
    Norie, no i haven't used regular expressions, i have never explored them. I understand what you say about the possible combinations for find 'n' replace but in this instance it doesn't seem too many and although i don't understand regex what you have just explained seems like a lot of work.

    But of course i don't have the experience there so
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  12. #12
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Simon

    How does what I explain seem like a lot of work?

  13. #13
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Norie, the OP seems to have some understanding of regex but if we can't get to the bottom of the problem it is hard to help....

    regex is complicated for beginners by the way......it has it's own learning curve you have to admit.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  14. #14
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Norie, maybe i see it like that because the VBA (a UDF) for it would have to include Find, Replace, Match along with setting references to Microsoft VBScript Regular Expressions and create a vbscript object.

    Anyway to be more helpful to the Op here's some help in this forum:
    Brettj's RegEx and a discussion here
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  15. #15
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Norie
    Simon

    How does what I explain seem like a lot of work?
    Learning regular expressions is hard work. Copying a provided example and using it is simple, learning to properly use regular expressions to parse a string to perform the required result requires an understanding that does not come easily.

    If you think it is so simple, give me a regular expression that extracts the proper value to address someone by in a named expression, where you can have values such as

    John Smith
    Dick Van Dyke
    Peter Alan Coe
    Baron Hubert de Coubertin
    Ian St John
    Peter Gray Snr.

    etc. etc.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  16. #16
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    lucas

    I realise it can be complicated using RegExp, I'm not expert on it myself.

    As to what the expression posted by the OP, it just looks over-complicated.

    It's easy to extract all the numbers, if that's what's required, from a text string using RegExp.

  17. #17
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Simon

    Why would it need to include Find/Replace?

    What about using VBA text functions like Join?

    xld

    I'm not saying it's easy to learn how to use RegExp 'properly' or 'efficiently'.

  18. #18
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    I know this is adding fuel to the fire but in RegEx do you not need to know the combinations of what to look for and what to replace it with?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  19. #19
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Indeed you do, but you can string the different combinations together in a much neater, but totally incomprehensible, expression, just the one.
    Last edited by Bob Phillips; 05-12-2008 at 10:04 AM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  20. #20
    VBAX Newbie
    Joined
    May 2008
    Posts
    4
    Location
    Hi Steve,

    It was not intentionally done. By mistake I did it. I am sorry.

    Regards,
    Mahesh.
    Last edited by ishwaar; 05-12-2008 at 09:53 AM.

Posting Permissions

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