0x2bad
0x2bad

Reputation: 318

Find everything but version number

i have this text

Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

58.0.3029 Copyright 2011 Google Inc.

I want is to find everything but

58.0.3029

I use this to find the pattern

\d+(\.\d+\.\d+)

So I have to find all but, the closest I could make was this

[\D+]+([\.\D+][\.\D+])

but it excludes other numbers 5.8 and 2011 too which I don't want to happen

Can you help me to find the right regex for that?

I use http://www.regexpal.com/ to test

I'm using a tool that's been developed with C#

Upvotes: 4

Views: 51

Answers (3)

KevBot
KevBot

Reputation: 18888

If you want to capture everything but the version number, you can use the following:

([\s\S]*)\b\d+(?:\.\d+){2,}\s*([\s\S]*)

Regex101 Example

Upvotes: 0

Jan
Jan

Reputation: 43169

Use anchors (in multiline mode):

^\d[\d.]+
# match the start of the line
# require one digit
# followed by digit(s) and dot(s)

And replace the found match with ''. See a demo on regex101.com.

Upvotes: 1

degant
degant

Reputation: 4981

To get everything but the version number:

([\s\S]*)\b(\d+\.\d+\.\d+)\b([\s\S]*)

Replace with: $1$3

Regex101 Demo

Output:

Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

 Copyright 2011 Google Inc.

Upvotes: 0

Related Questions