regular expressions : g-code

Cholotron 161 Reputation points
2023-08-29T19:10:16.4033333+00:00

Using regular expression, I need to remove the following

Original Strings :

N1G28G91Y0.Z0.

N12G44Z2.H22M8

N333(.69" THDMILL)

String always start with an "N" follow by a number, 1, 2 up to 3 digits

Final Result :

G28G91Y0.Z0.

G44Z2.H22M8

(.69" THDMILL)

Thank you All
john

Developer technologies VB
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-08-30T02:36:48.48+00:00

    Hi @Cholotron ,

    Use the regular expression ^N\d{1,3} to match an "N" follow by a number, 1, 2 up to 3 digits at the beginning of the string

        Function RemoveNWithDigits(input As String) As String
            Dim pattern As String = "^N\d{1,3}"
            Dim regex As New Regex(pattern)
            Dim output As String = regex.Replace(input, "")
            Return output
        End Function
        
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.