Shivam Tyagi
Shivam Tyagi

Reputation: 168

Regular Expression for any string which takes all the characters prior to .pdf

Can any one give the regular expression for checking a string prior to .pdf

For example: I want the text angular from the string angular.pdf#2345 or angular.pdfthis.

Upvotes: 0

Views: 291

Answers (3)

Nina Scholz
Nina Scholz

Reputation: 386680

You could use a regular expression with a positive lookahead.

/.*(?=\.pdf)/

console.log('angular.pdf#2345'.match(/.*(?=\.pdf)/));

Upvotes: 2

Aakash Verma
Aakash Verma

Reputation: 3994

Seems your example clarifies what you really want.

str.substring(0,str.indexOf(".pdf"))

Upvotes: 1

Jonas Köritz
Jonas Köritz

Reputation: 2644

What about this:

(.*)\.pdf.*

The first matching group will contain the string prior to .pdf.

See this example.

Upvotes: 1

Related Questions