Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

node.js - partial regex match in javascript

I want to valiadte a dynamic string which comes in different parts of string in an SMS (more than 160 characters as 2 SMS). i have the complete template with me where i need to check if this incoming part is valid or no.

I have a long regex, as mentioned below:

let template = 'Dear .+, your order is shipped and will be delivered to you on .+ by .+ .+. Request you to keep your .+ card ready with you for verification'

I want to match if the below string is present in the regex

let smsPart = ' you to keep your PAN card ready with you for verification'

Note: the part may start from anywhere, depending on the dynamic input in the main template.. in the above example it starts from " you to keep"

If this is not possible with regex, then can anyone suggest a workaround to deal with this situation.

Thanks :)

Sample Code:

let template = 'Dear .+, your order is shipped and will be delivered to you on .+ by .+ .+. Request you to keep your .+ card ready with you for verification'

let smsPart1 = 'Dear James, your order is shipped and will be delivered to you on 11/01/21 by 7 PM. Request'
let smsPart2 = ' you to keep your PAN card ready with you for verification'


console.log((smsPart1+smsPart2).match(template))

need help to verify if part by part matches.

For example: want to do something like below, but it doesnt work with regex

template.includes(smsPart1) //In this case there is a dynamic value represented as .+
question from:https://stackoverflow.com/questions/65915047/partial-regex-match-in-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...