首页 \ 问答 \ Javascript正则表达式和日语符号(Javascript regex & Japanese symbols)

Javascript正则表达式和日语符号(Javascript regex & Japanese symbols)

我使用字符串对象的search()方法来查找正则表达式和字符串之间的匹配。

它适用于英语单词:

"google".search(/\bg/g) // return 0

但是这段代码对日语字符串不起作用:

"アイスランド語".search(/\bア/g) // return -1

如何更改正则表达式以查找日语字符串和正则表达式之间的匹配?


I use the search() method of the string object to find a match between a regular expression and a string.

It works fine for English words:

"google".search(/\bg/g) // return 0

But this code doesn't work for Japanese strings:

"アイスランド語".search(/\bア/g) // return -1

How can I change the regex to find a match between Japanese strings and a regular expression?


原文:https://stackoverflow.com/questions/7900539
更新时间:2022-09-25 08:09

最满意答案

如果您只希望它在第二个大括号位于行的开头时执行此操作:

perl -0777 -pi -we's/}\n\n}/}\n}/g' filename

即使它是缩进的:

perl -0777 -pi -we's/}\n(\n[^\S\n]*(?=}))/}$1/g' filename

如果“空”行或第一个大括号之后可能有额外的空格:

perl -0777 -pi -we's/(}[^\S\n]*\n)[^\S\n]*\n([^\S\n]*(?=}))/$1$2/g' filename

If you only want it to do it when the second curly brace is at the beginning of the line:

perl -0777 -pi -we's/}\n\n}/}\n}/g' filename

If even if it is indented:

perl -0777 -pi -we's/}\n(\n[^\S\n]*(?=}))/}$1/g' filename

If there might be extra whitespace on the "empty" line or just after the first curly brace:

perl -0777 -pi -we's/(}[^\S\n]*\n)[^\S\n]*\n([^\S\n]*(?=}))/$1$2/g' filename

相关问答

更多
  • 如果您正确格式化了第一个代码段 while (1){ if (i>=n&&j<0) break; else if (j<0) if (Arr[i]) c++; else if (i>=n) if(Arr[j]) c++; else if (Arr[i]==1&&Arr[j]==1) c+=2; i ...
  • 以下是对ES6模块的一个很好的解读: https ://24ways.org/2014/javascript-modules-the-es6-way/ 这两者之间的区别在于,当您不导出default模块时,将使用方括号{} 。 你不能重命名它们! 没有括号,导出的函数,变量等必须是default 。 您可以随意命名myFunction 。 export default myFunction; ... import somethingsomethingDangerZone from "myfunction ...
  • 带有大括号的块是实例初始化块。 Oracle Java教程的这个页面有更多关于它的信息。 另请参阅: 实例初始化程序与构造函数有何不同? The block with the curly brackets is an instance initializer block. This page from Oracle's Java Tutorials has some more info about it. Also see: How is an instance initializer different ...
  • 我可以推荐迭代吗? 如果您正在使用价值观,这是完美的: ul each val, index in ['zero', 'one', 'two'] li= val li= Some Text 但是,如果你只是想重复一行,你可以这样做: ul while n < 4 li= Sometext Jade的一本方便指南 Might I recommend iteration? If you are working with values this ...
  • 只有一条语句时,您可以省略花括号。 for (var x in obj) { console.log(x); } 可以变成 for (var x in obj) console.log(x); 但如果你有 for (var x in obj) { console.log(x); console.log(x); } 它会需要大括号。 这有点不一致。 例如,它适用于for , while和if ,但不适用于try或catch 。 为了一致性,我总是使用大括号。 You ca ...
  • 你可以做一个否定: if(!empty($data) && $data != 'unanswered') echo $data; You could do a negation instead: if(!empty($data) && $data != 'unanswered') echo $data;
  • 据我所知,没有关于它们的官方文档,但是它们与New Location(LandscapeSize, LandscapeSize)一起使用以将您的Landscape变量实例化为Location对象的空数组。 如果您不使用括号,编译器会认为您正在尝试实例化单个 Location对象,将LandscapeSize, LandscapeSize传递给构造函数。 否则,括号用于填充数组: Landscape = New Location(LandscapeSize, LandscapeSize) {New Locat ...
  • 如果您只希望它在第二个大括号位于行的开头时执行此操作: perl -0777 -pi -we's/}\n\n}/}\n}/g' filename 即使它是缩进的: perl -0777 -pi -we's/}\n(\n[^\S\n]*(?=}))/}$1/g' filename 如果“空”行或第一个大括号之后可能有额外的空格: perl -0777 -pi -we's/(}[^\S\n]*\n)[^\S\n]*\n([^\S\n]*(?=}))/$1$2/g' filename If you only ...
  • 您可以将匹配对象传递给re.sub的lambda并替换{...}所有换行符: import re text = 'Some text\nwith a {variable\n} value"' print(re.sub(r'{.*?}', lambda m: m.group().replace("\n", ""), text, flags=re.DOTALL)) 参见在线Python 3演示 请注意,这个正则表达式不需要re.MULTILINE标志,因为它没有重新定义行为的^ / $锚点,并且您不需要在当前 ...
  • 此功能与jQuery无关,称为模板文字 。 这是一个新功能,出现在ES6中 。 它将评估${abc + def}并将值放入字符串中。 这在ES6中 `${abc+ def}` 在ES5中相当于此 "" + (abc + def) + "" This feature is not related to jQuery and is called template literal. It is a new feature, appeared in ES6. It will ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)