在正则表达式匹配中包含短划线/连字符

时间:2017-12-04 20:03:49

标签: python regex python-3.x

我试图在Python 3中修改我的正则表达式搜索,将破折号包含为有效。现在我有:

class App extends Component {
  constructor(props) {
    super(props);
    this.state = { 
      ...
      selection: {
        country: null,
        state: null,
        city: null
      }
    };

    this.handleClick = this.handleClick.bind(this);
  }

  handleClick(getSelection) {
    return location => {
      const selection = getSelection(location);
      this.setState({
        selection: Object.assign({}, this.state.selection, selection)
      };
    };
  }

  render() {
    return (
      <div>
        ...
        <LocationList title="Country"
                      selection={this.state.selection.country}
                      onClick={this.handleClick(country => ({ country, state: null, city: null }))}
                      // other props
        />
        <LocationList title="State"
                      selection={this.state.selection.state}
                      onClick={this.handleClick(state => ({ state, city: null }))}
                      // other props
        />
        <LocationList title="City"
                      selection={this.state.selection.city}
                      onClick={this.handleClick(city => ({ city }))}
        />
      </div>
    );
  }
}

哪个匹配评论为match = re.search('(?<=!search:)\w+', comment) !search:xx等情况。如何修改它以便 接受连字符?

我喜欢!search:xxx之类的匹配。我尝试在regex101上玩它,但无法让它工作。

提前感谢您的帮助!

0 个答案:

没有答案