简体   繁体   English

正则表达式模式,用于检查字符串中每个单词的第一个字母,如果它是Javascript中的大写字母

[英]Regex Pattern for checking the first letter of each word in a string if its Uppercase in Javascript

for example my string is Foo Bar. 例如我的字符串是Foo Bar。 this string should match the pattern. 此字符串应与模式匹配。

if the string is Foo bar. 如果字符串是Foo bar。 the string should not match. 字符串不应该匹配。

if the string is Foo Bar Foobar the string should match 如果字符串是Foo Bar Foobar,则字符串应该匹配

if the string is Foo. 如果字符串是Foo。 it should also match. 它也应该匹配。

so far I only have this pattern 到目前为止我只有这种模式

 (^[A-Z]{1}.*(\s)?$)+

Basically I will only accept a string where each First letter of each word is Uppercase 基本上我只接受一个字符串,每个单词的每个首字母都是大写字母

我会看看你的字符串是否与以下内容不匹配:

/\b[a-z]/

You can try to use this regex: 您可以尝试使用此正则表达式:

^(\b[A-Z]\w*\s*)+$

Regex Demo 正则表达式演示

我以前用这个:

#(\s|^)([a-z0-9-_]+)#i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在JavaScript中将字符串中每个单词的首字母转换为大写 - Convert first letter of each word in a string to Uppercase in JavaScript 使用replace和regex来优化JavaScript中每个单词的第一个字母 - Using replace and regex to capitalize first letter of each word of a string in JavaScript 在 JavaScript 中获取字符串中每个单词的首字母 - Get first letter of each word in a string, in JavaScript 如何使用正则表达式选择字符串中每个单词的首字母 - How to select first letter of each word of a string using regex 在JavaScript中将字符串中的第一个字母更改为大写 - Change first letter in string to uppercase in JavaScript JavaScript:如何返回字符串中每个单词的首字母 - JavaScript: how to return the first letter of each word in a string Javascript错误返回提供的字符串,每个单词的首字母大写 - Javascript error with Returning the provided string with the first letter of each word capitalized Javascript使用循环返回字符串中每个单词的第一个字母的位置 - Javascript Return the location of the first letter of each word in a string using a loop 只有当lengh> 2时,Javascript才会将字符串中每个单词的首字母大写 - Javascript capitalize first letter of each word in a string only if lengh > 2 似乎无法将每个单词的第一个字母大写 - Can't seem to uppercase the first letter in each word
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM