正则表达式如何实现,匹配以*开头的一行?

匹配下面代码中以*开头的行

 public class TransferForm extends BaseObject{
    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column GC_TRANSFER_FORM.FORM_ID
     *
     * @mbggenerated Wed Jan 04 13:58:02 CST 2017
     */
    private String formId;

}

3个回答

/^\s**[^\n]+$/gm,记得加m选项,多行匹配


<textarea id="ta">
    public class TransferForm extends BaseObject{
    /**
    * This field was generated by MyBatis Generator.
    * This field corresponds to the database column GC_TRANSFER_FORM.FORM_ID
    *
    * @mbggenerated Wed Jan 04 13:58:02 CST 2017
    */
    private String formId;

    }
</textarea>
<script>
    var s = ta.value, mc = s.match(/^\s*\*[^\n]+$/gm);
    console.log(mc)
</script>

正则表达式为:^\s**

q1010174887
q1010174887 ^\*.*
接近 4 年之前 回复
u013179958
CSDNRGY 回复tang_cheng: 无法匹配
接近 4 年之前 回复
tang_cheng
tang_cheng 正则表达式为:^\s*\* (全角的\换成半角的)
接近 4 年之前 回复

[test@localhost shell]$ cat test.txt
public class TransferForm extends BaseObject{
/**

  • This field was generated by MyBatis Generator.
  • This field corresponds to the database column GC_TRANSFER_FORM.FORM_ID *
  • @mbggenerated Wed Jan 04 13:58:02 CST 2017 */ private String formId;

}
[test@localhost shell]$ cat test.txt |sed 's/^[[:space:]]*//g'|grep '^*'

  • This field was generated by MyBatis Generator.
  • This field corresponds to the database column GC_TRANSFER_FORM.FORM_ID *
  • @mbggenerated Wed Jan 04 13:58:02 CST 2017 */_

cat test.txt |sed 's/^[[:space:]]*//g'|grep '^*'
先将行首的空格都去掉,之后筛选出以*开头的行。
不知道你是不是这意思~~~

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐